I'm trying to catch scenarios if there is no autorelease pool in place.
This is my test app.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[self performSelectorInBackground:@selector(bgOperation:) withObject:nil];
}
- (void)bgOperation:(id)obj
{
NSString *string [[[NSString alloc] init] autorelease];
}
I've tried setting the breakpoint objc_autoreleaseNoPool.
I've tried profiling with Instruments / Leaks.
OSX 10.7.5 XCode 4.3.3 Targeting 10.6, AutomaticRefCounting = NO, GarbageCollection = Unsupported.
I understand NSApplication includes it's own autorelease pool. But my understanding was that each call to performSelectorInBackground: needed it's own autorelease pool.
Update from the suggestions:
I tried this..
in main.m, no luck.
int main(int argc, char *argv[])
{
NSString *junk = [[[NSString alloc]init]autorelease];
return NSApplicationMain(argc, (const char **)argv);
}
And this..
In my appDelegate, also no result.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[NSThread detachNewThreadSelector:@selector(bgOperation:)
toTarget:self
withObject:nil];
}
And this..
With pthreads in my main.m
void *doJunk(void *ptr){
NSString *junk = [[[NSString alloc]initWithString:@"string with no pool"]autorelease];
NSLog(@"%@", junk);
pthread_exit(NULL);
}
int main(int argc, char *argv[])
{
pthread_t thread;
pthread_create(&thread, NULL, doJunk, NULL);
return NSApplicationMain(argc, (const char **)argv);
}
I understand that due to the OS level maybe nothing is leaking (still haven't confirmed), but when I target 10.6 I see a number of "No Pool" messages in the logs. If it only leaks due to the OS level, then I need a way to catch these scenar