Why isn’t my autoreleased object getting released?

Posted by zoul on Stack Overflow See other posts from Stack Overflow or by zoul
Published on 2011-02-25T19:58:51Z Indexed on 2011/02/26 7:25 UTC
Read the original article Hit count: 478

Hello. I am debugging a weird memory management error and I can’t figure it out. I noticed that some of my objects are staying in memory longer than expected. I checked all my memory management and finally got to the very improbable conclusion that some of my autorelease operations don’t result in a release. Under what circumstances is that possible? I created a small testing Canary class that logs a message in dealloc and have the following testing code in place:

NSLog(@"On the main thread: %i.", [NSThread isMainThread]);
[[[Canary alloc] init] autorelease];

According to the code we’re really on the main thread, but the dealloc in Canary does not get called until much later. The delay is not deterministic and can easily take seconds or more. How is that possible? The application runs on a Mac, the garbage collection is turned off (Objective-C Garbage Collection is set to Unsupported on the target.) I am mostly used to iOS, is memory management on OS X different in some important way?

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about mac