Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a lot of topics to cover here, but I'll start with the recommended approach:</p> <p>METHOD_003</p> <pre><code>-(void)viewDidLoad { NSLog(@"VIEW: Single ... Loaded"); self.pickerData = [NSArray arrayWithObjects:@"A", @"B", @"C", nil]; [super viewDidLoad]; } </code></pre> <p>Note: thanks to Vladimir for the <a href="https://stackoverflow.com/posts/2245727/edit">reminder to nil-terminate</a>.</p> <p>Now, for the details:</p> <p>METHOD_001 does the exact same thing as METHOD_003, but it takes a few more lines of code.</p> <p>METHOD_002 has a memory leak because you <code>alloc</code> the array, and then also <code>retain</code> it. This results a total retain count of 2. When you release the array in your <code>dealloc</code> method, the count will be reduced to 1, so the array will not be released from memory.</p> <p>Even if you remove the extra <code>retain</code> from METHOD_002, it will not do two very important things:</p> <ol> <li><p>It will not send the proper <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/KeyValueCoding/KeyValueCoding.html" rel="nofollow noreferrer">KVC/KVO notifications</a>. Cocoa does a lot of very convenient things behind-the-scenes when you use a property accessor, so unless you have a good reason not to, using the accessors is highly recommended.</p></li> <li><p>It will not automatically release any old data that was stored in <code>pickerData</code>. This is not a concern in <code>viewDidLoad</code>, but if you were in a different method, it <em>would</em> make a difference, so it is best to just get in the habit of using the accessors unless you have a specific reason not to.</p></li> </ol>
 

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