RE: How to track down a double release?
RE: How to track down a double release?
- Subject: RE: How to track down a double release?
- From: Brant Sears <email@hidden>
- Date: Thu, 16 Oct 2003 15:35:17 -0700
I tried this and it didn't have any effect. So, I created a brand new Cocoa
app and created a controller object and made it the app delegate, then
implemented applicationDidFinishLaunching and put in code like this:
-(void)applicationDidFinishLaunching:(id)notification
{
NSString * foo = [[NSString alloc] initWihtCString:"foo"];
[foo autorelease];
[foo release];
}
And I turned on both NSZombieEnable and also
NSAutoreleaseFreedObjectCheckEnabled. I turned them on by clicking the
target, then the executable and putting them into the GUI as environmental
variables. I tried setting them to YES and when that didn't work, I tried
setting them to 1. In all cases, this program just gets an EXC_BAD_ACCESS.
This was using 10.2.6 and the Dec 2002 Tools.
So, finally I moved the same code over to Panther and xCode. It is version
7B7F. On that system, I got a double free message in the console. However, I
got the double free message whether I had these variables set or not. They
didn't seem to have any effect on the situation.
Then, I tried moving the release call into another thread. So, instead of
releasing from inside of applicationDidFinishLaunching, I detach another
thread (code below) and send over the object which then releases it. In this
case, I did not get a double free message, I got EXC_BAD_ACCESS. I put in a
sleep call in the main thread so that I could be sure the thread I detached
had time to do its free first before the autorelease pool gets popped.
In this case, even with both NSZombieEnable and also
NSAutoreleaseFreedObjectCheckEnabled set to YES in xCode, I get
EXC_BAD_ACCESS. I do not get a double free message, and I get no other help
as to what's going wrong. In fact, the stack when it blows up in this case,
looks just like what my app is doing. The code looks like this:
-(void)applicationDidFinishLaunching:(id)notification
{
NSString *foo = [[NSString alloc] initWithCString: "foo"];
[foo autorelease];
[NSThread detachNewThreadSelector:@selector(bar:) toTarget: self
withObject: foo];
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow:
1.0]];
}
-(void)foo:(id)obj
{
[obj release];
}
Is there any way to track this problem down? I just wish the Autorelease
pool had some way of telling me *what object* it is trying to release when
it blows up. I think that I should be able to dump the contents of a pool
and check to see if they are valid. It seems like some of the NSDebug stuff
is trying to enable that facility, but maybe I'm using it wrong? Or its
broken for multi-threaded apps?
Turning on the environmental variables does nothing as far as I can tell.
Brant Sears
>
----------
>
From: Sascha Matzke
>
Sent: Thursday, October 16, 2003 7:39 AM
>
To: Brant Sears
>
Cc: email@hidden
>
Subject: Re: How to track down a double release?
>
>
Quoting Brant Sears <email@hidden>:
>
>
> I have a situation (totally repeatable) where my app blows up when
>
> an autorelease pool gets cycled. It is a multi-threaded app (I don't
>
> know that it matters.)
>
>
Try setting NSZombieEnable=YES as environment variable.
>
>
See: http://www.cocoadev.com/index.pl?NSZombieEnabled
>
>
>
Sascha
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.