Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The object isn't being released, it's being <em>autoreleased</em>. Autorelease is like deferred cleanup, it means "I'm done with this, feel free to get rid of it later". Sometimes another part of the code, like a function that yours was called from, will pick up the object (<em>retain</em> it) before the autorelease occurs.</p> <p>Autoreleasing is managed by a class called <code>NSAutoreleasePool</code>. The class maintains a stack of pools, and when an object is autoreleased, it is added to the topmost pool on the stack. Draining a pool causes it to release all of the objects that have been added to it - and if any have been released enough, they will be deallocated. You don't need to manage the <code>NSAutoreleasePool</code> instances directly if you don't want to; you can just put your code into an <code>@autoreleasepool{}</code> block and the compiler will insert a static <code>NSAutoreleasePool</code> instance.</p> <p>There are three approaches you can take to remove this message. One, which works on both the Mac and iPhone, is the one suggested by KennyTM - add an autorelease pool around you code that uses autoreleased objects. You need one for each thread where you autorelease Cocoa objects, more is possible but usually one is sufficient. The second alternative, though only if you're targeting Mac OS, is to enable garbage collection. That won't solve all of your problems but does mean that unreferenced objects are automatically removed.</p> <p>On both platforms you can also use Automatic Reference Counting, which instructs the compiler to take care of memory management for you. You still need to put the autorelease pools in place, and there are some "interesting" interactions with toll-free bridging, but on the whole if you're struggling with reference counting it's probably best to automate it.</p> <p>If you're not familiar with retain counts and autorelease pools, you may have other memory management problems in your code. I recommend you use the static analyser on your project (choose "Build &amp; Analyze" from Xcode's build menu) and address any issues it raises.</p>
 

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