Update: This leak has been resolved. If you get similar leaks and your application is multithreaded, you are most likely making UIKit calls from the background thread; use, for example, [NSThread performSelectorOnMainThread:] to route UIKit calls to the main thread, which is the only place they are allowed .
I have been running leaks in my current project to find leaks recently, and I continue to run into these โleaks,โ which from what I can say are not leaks. The following code, taken directly from the project, has two leaks according to the leaks:
- (NSArray *)areaForIndex:(int)index { NSMutableArray *a = [NSMutableArray arrayWithArray: [world retrieveNeighborsForIndex:index]];
Leak 1 goes away if I change the first line to: (see Update 2-3)
Leak 2 goes away if I change the last line to:
return a;
I cannot, unfortunately, do this with leak 1, because I am imposing an immutable array into a mutable one. However, arrayWithArray should be auto-advertising, one way or another, so from what I can say, this should not leak anything. Any ideas why this is happening?
Update: I tested this on both the device and the Simulator. A leak there on both. However, on the Simulator, I get additional information about this leak:
The leak history is as follows:
What I can distinguish from the above is that the auto-implemented array is somehow saved twice, and then auto-implemented, leaving the count value at 1. I donโt know where and why, though ...
Update 2 and 3: I tried changing the line for leak 1 to:
NSMutableArray *a = [[[NSMutableArray alloc] initWithArray: [world retrieveNeighborsForIndex:index]] autorelease];
I thought this fixed the leak, but in the end this did not happen. Therefore, I am still at a loss.