Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>calling</p> <pre><code>self = [super init]; </code></pre> <p>May return nil if the superclass cannot initialize itself for some reason or other, including memory being unavailable, or certain prerequisites have not been met. If that is the case, you don't want to be trying to set variables of self, or set self as a delegate, or add self to an array, if self is nil.</p> <p>The autorelease pool is something created upon every event the iPhone sends your application. It is created before any code runs, and released after all your code is done, for each event. Any objects that you call <code>autorelease</code> on will be put into the current autorelease pool. Any objects in the autorelease pool will be released as many times as they were added, after your code completes. In this way, you don't have to worry about who's responsible for releasing an object created by one method and returned to another method.</p> <p>You can create your own autorelease pools as necessary.</p> <pre><code>str = [[NSString alloc] initWithString:@"Hi there!"]; </code></pre> <p>This line creates a string that is not in an autorelease pool, so you have to release it manually. Simply writing</p> <pre><code>@"Hi there!"; </code></pre> <p>returns a string that you don't have to worry about releasing. Extending your previous example:</p> <pre><code>str = [[[NSString alloc] initWithString:@"Hi there!"] autorelease]; </code></pre> <p>would be another method of creating a string you don't need to worry about releasing.</p> <p>One difference between garbage collection and autorelease pools is that garbage collection works with circular references. Using autorelease pools, you don't want to have two objects that retain each other and hope that once nothing else refers to them, they will go out of existence; they won't.</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