• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [pool release] error
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pool release] error


  • Subject: Re: [pool release] error
  • From: Robert Marini <email@hidden>
  • Date: Fri, 26 Dec 2008 11:44:31 -0500

So... firstly, - tempNum = [[NSDecimalNumber alloc] init] at the end of a method after assigning an autoreleased instance of NSDecimalNumber to it - why? I'm trying to understand the logic in this and can't. As near as I can tell you aren't doing any book- keeping of this later on.

What I would imagine is the cause of the error based on my ten mile high overview is that at some point in your code you set decimalNumber to be an instance of an autoreleased object (in updateDecimalNumberWithFraction). You then release the Fraction instance in your main method which triggers this object to dealloc. Now the pool drains but the object it expects to release isn't in existence anymore. If you are going to assign it an autoreleased instance, you should explicitly -retain it. NSZombie is your friend here.

-rob.


On Dec 26, 2008, at 11:29 AM, Steve Wetzel wrote:

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 (email@hidden)

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:
This email sent to email@hidden

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

References: 
 >[pool release] error (From: Steve Wetzel <email@hidden>)

  • Prev by Date: Re: [pool release] error
  • Next by Date: Re: modifier key query
  • Previous by thread: Re: [pool release] error
  • Next by thread: Re: [pool release] error
  • Index(es):
    • Date
    • Thread