0

I'm working on an app and have 1 leak left. The leaked object is NSAutoreleasePool, size is 32 bytes. In the stacktrace only foundation methods are called. I have no clue how to resolve this.

In simulator no leaks reported, on the device only this leak.

Any idea's?

The autoreleasepool is one I define myself.

In my viewcontroller I call:

[self performSelectorInBackground:@selector(getDetailInfo:) withObject:self.infoID];

This is getDetailInfo:

- (void)getDetailInfo:(NSString *)theID {

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    DetailInfo *info = [[DataProvider sharedInstance] getDetailInfo:theID]; //the return object is autoreleased.
    [self performSelectorOnMainThread:@selector(updateViewWithDetailInfo:) withObject:info waitUntilDone:NO];

    [pool release];
}

Some additional info:

For testing I changed all my methods which were called using performSelectorInBackground to run on the main thread and removed those autoreleasepools.

I still received the leak on the NSAutoreleasePool. Today I learned that you can show the "Library name" in the stacktrace in instruments. :-) I copied it below and you can see the MapKit on line 6 and 7.

0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 Foundation +[NSAutoreleasePool allocWithZone:]
5 CoreFoundation +[NSObject(NSObject) alloc]
6 MapKit TileCachePrivate::runCacheThread()
7 MapKit _runCacheThread(void*)
8 libSystem.B.dylib _pthread_start
9 libSystem.B.dylib thread_assign_default

This the code for the mapview:

    MKMapView *omgeving = [[MKMapView alloc] initWithFrame:CGRectMake(11, 22, 298, 297)];
    omgeving.delegate = nil;
    [self addSubview:omgeving];
    [omgeving release];     

If I comment out the MapView code, no leak. If I leave it in, I get the Leak.

Leaked Object       #   Address     Size    Responsible Library Responsible Frame
NSAutoreleasePool       0x6a52e50   32      Foundation          +[NSAutoreleasePool allocWithZone:]

Thanks for all the comments so far. Any suggestions?

McDJ
  • 767
  • 2
  • 11
  • 28
  • Where is the autorelease pool? Is this the one in main.m? Or is it one you are defining yourself. If that is the case you need to either drain or release the autorelease pool when you are done with it. – DHamrick Nov 11 '10 at 16:24
  • DHamrick is right. Can you show us the code where you're allocating the pool that you are leaking, and where you are draining it? – Ryan Nov 11 '10 at 16:30
  • I've edited the post to include the code with the autoreleasepool. – McDJ Nov 11 '10 at 16:41
  • Looks like a false positive. You're using that autorelease pool correctly. Are you seeing your memory usage actually go up if you call that method a bunch of times? I don't see how this can be a leak. – Ryan Nov 11 '10 at 18:34

2 Answers2

2

Known issue: https://devforums.apple.com/message/282497#282497

Thanks for thinking along.

McDJ
  • 767
  • 2
  • 11
  • 28
0

I have found a leaked NSAutoreleasePool often points at the wrong NSAutoreleasePool. Do you use a NSAutoreleasePool in DataProvider's getDetailInfo? What about the caller?

I've read before that draining an outer NSAutoreleasePool is supposed to drain inner ones, but I haven't found this to be the case.

…Also, drain is preferred over release on NSAutoreleasePool. That isn't your problem, though.

Steven Fisher
  • 44,462
  • 20
  • 138
  • 192
  • I don't use NSAutoreleasePool in the DataProvider. I do a SOAP call in the DataProvider, parse JSON, create an autoreleased object and return this to the viewController. Then update the view on the main thread. – McDJ Nov 11 '10 at 16:58