Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>David's answer is correct but I would advice reading up on your memory management. </p> <p>If you are synthesizing properties then it is a lot easier to use the getters and setters and let them do the memory management for you. The exception being in your init/dealloc methods where you should try to directly use the ivars to avoid any potential side effects of using the getters/setters.</p> <p>With the two lines david highlighted</p> <pre><code>seminareArray = [[NSMutableArray alloc] init]; // owned seminareArray = [NSMutableArray arrayWithCapacity:10]; // autoreleased </code></pre> <p>You could potentially use either if the memory management was done correctly.</p> <p>The first line on its own is correct as it creates an instance of <code>NSMutableArray</code> with a retain count of +1 then assigns it straight to the ivar.</p> <p>Then as David pointed out the second line replaces this with an autoreleased <code>NSMutableArray</code> so this line is superflous and crashes your program. The method <code>arrayWithCapacity:</code> is not simply setting the capacity of the array it is giving you a new autoreleased array.</p> <p>If you wanted to use an autoreleased <code>NSMutableArray</code> then you would need to use the setter either with dot notation of passing a message:</p> <pre><code>self.seminareArray = [NSMutableArray arrayWithCapactiy:10]; OR [self setSeminareArray:[NSMutableArray arrayWithCapcity:10]]; </code></pre> <p>By simply referencing things straight to <code>seminareArray</code> you are avoiding the getters/setters you synthesized and therefore are responsible for all of your memory management.</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