问题
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?
回答1:
Known issue: https://devforums.apple.com/message/282497#282497
Thanks for thinking along.
回答2:
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.
来源:https://stackoverflow.com/questions/4156517/leaking-nsautoreleasepool