Note that there are some explanatory texts on larger screens.

plurals
  1. POLeaks (instrument) reports leaks in autoreleased objects
    primarykey
    data
    text
    <p><em>Update: this leak has been solved. If you are getting similar leaks and your application is multi-threading, you are most likely making UIKit calls from a background thread; make use of e.g. <code>[NSThread performSelectorOnMainThread:]</code> to route UIKit calls out to the main thread, which is</em> <strong>the only place where they are allowed</strong>.</p> <p>I've been running Leaks on my current project to find leaks lately, and I keep running into these "leaks" which from what I can tell aren't really leaks. The following code, taken directly from the project, has two leaks, according to Leaks:</p> <pre><code>- (NSArray *)areaForIndex:(int)index { NSMutableArray *a = [NSMutableArray arrayWithArray: [world retrieveNeighborsForIndex:index]]; // leak 1 [a insertObject:[references objectAtIndex:index] atIndex:0]; return [NSArray arrayWithArray:a]; // leak 2 } </code></pre> <p><strike>Leak 1 goes away if I change the first line to:</strike> (see Update 2-3)</p> <p>Leak 2 goes away if I change the last line to:</p> <pre><code> return a; </code></pre> <p>I can't unfortunately do that with leak 1 because I'm casting an immutable array into a mutable one. Still, arrayWithArray is supposed to autorelease, anyway, so from what I can tell, it shouldn't leak anything. Any ideas why this is happening?</p> <p>Update: I've tested this on both the device and the Simulator. The leak is there on both. However, on the Simulator I get some additional information about this leak:</p> <p>The history for the leak goes as follows:</p> <pre><code># | Category | Event Type | Timestamp | RefCt | Address | Size | Responsible Library | Responsible Caller --+----------+-------------+ 0 | CFArray | Malloc | 00:09.598 | 1 | 0x474f6d0 | 48 | asynchro | -[muddyGrid areaForIndex:] 1 | CFArray | Autorelease | 00:09.598 | | 0x474f6d0 | 0 | Foundation | NSRecordAllocationEvent 2 | CFArray | CFRetain | 00:09.598 | 2 | 0x474f7d0 | 0 | Foundation | -[NSCFArray retain] 3 | CFArray | CFRelease | 00:09.611 | 1 | 0x474f7d0 | 0 | Foundation | NSPopAutoreleasePool </code></pre> <p>The things I can discern from the above is that the autoreleased array is somehow retained twice and then autoreleased, leaving retain count at 1. No idea where or why though...</p> <p>Update 2 &amp; 3: I tried changing the line for Leak 1 to:</p> <pre><code> NSMutableArray *a = [[[NSMutableArray alloc] initWithArray: [world retrieveNeighborsForIndex:index]] autorelease]; </code></pre> <p>I thought this removed the leak, but it didn't, ultimately. So I'm still at a loss.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload