PerformSelectorInBackground leaking on device
While it seems to not pose a problem on the simulator, using performSelectorInBackground
on the device causes memory leaks. Or at least that's what Instruments indicates. Looking at the code I don't have a single clue what the cause开发者_开发技巧 could be.
I tried to strip the affected code to a bare minimum but still strangely Instruments keeps showing a leak every time this piece of code is executed.
Anything unusual going on here?
//In viewcontrollerA:
-(void)mainLoop
{
[self.viewControllerB performSelectorInBackground:@selector(calculateTotals) withObject:nil];
//This gives the same problem
//[NSThread detachNewThreadSelector:@selector(calculateTotals) toTarget:self.viewControllerB withObject:nil];
//UI stuff ...
}
//viewControllerB:
-(void)calculateTotals
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//Heavy calculations ...
[pool release];
}
Edit: I'm still looking into this and it seems that the leak is caused by the fact that somewhere down the stack [NSThread start] is never followed by [NSThread exit]. So it appears like there is occasionally a thread which is kept running without ever ending it. Now my question is, is there something I could do to make end those 'hanging' threats manually?
Perhaps one of your threads is throwing an exception? Exceptions in threads don't get reported in the debug console, you have to catch the exception in the thread.
精彩评论