Does anyone know why the follow code produces an error on [pool release]?. I get the following error : "*** -[NSDecimalNumber release]: message sent to deallocated instance 0x10c310". How am I overreleasing anything

#import "Fraction.h"
@implementation Fraction
-(id)init {
        if(self = [super init]) {
                numerator               = [[NSNumber alloc] initWithInt:0];
                denominator             = [[NSNumber alloc] initWithInt:1];
                decimalNumber   = [[NSDecimalNumber alloc] initWithString:@"0"];
        }
        return self;
}

-(void)dealloc {
        [numerator release];
        [denominator release];
        [decimalNumber release];
        [super dealloc];
}

-(void)updateDecimalNumberWithFraction {
NSDecimalNumber *tempNum = [NSDecimalNumber decimalNumberWithString: [numerator stringValue]]; NSDecimalNumber *tempDenom = [NSDecimalNumber decimalNumberWithString: [denominator stringValue]];
        
tempNum = [NSDecimalNumber decimalNumberWithString:[numerator stringValue]]; tempDenom = [NSDecimalNumber decimalNumberWithString:[denominator stringValue]];
        [decimalNumber release];
        decimalNumber = [tempNum decimalNumberByDividingBy:tempDenom];
        tempNum                 = [[NSDecimalNumber alloc] init];
        tempDenom               = [[NSDecimalNumber alloc] init];
}
-(void)setNumerator:(NSInteger)n {
        [numerator release];
        numerator = [NSNumber numberWithInteger:n];
        if([denominator intValue] != 0) {
                [self updateDecimalNumberWithFraction];
        }
}
-----------
//  main.m

#import <Cocoa/Cocoa.h>
#import "Fraction.h"

int main(int argc, char *argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        
        Fraction *f1 = [[Fraction alloc] init];
        
        NSInteger n1, d1;
        n1 = 1;
        d1 = 2;
        
        [f1 setNumerator:n1];
        [f1 setNumerator:n1];
        [f1 release];
    [pool release];
}

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to