Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For delegate you can check <a href="https://stackoverflow.com/questions/3396511/use-of-delegate-in-iphone-sdk/">use of Delegate in iphone sdk</a>. I have a long answer <a href="https://stackoverflow.com/questions/3396511/use-of-delegate-in-iphone-sdk/3397895#3397895">there</a>.</p> <pre><code>@property (nonatomic, retain) MyClass *obj; MyClass *tmpObj = [[MyClass alloc] init]; self.obj = tmpObj; [tmpObj release]; </code></pre> <p>Let's see what happens here. <code>[MyClass alloc]</code> allocates an object and you have retain count of 1. In the next line you are calling the setter which also retains. So you are increasing the retain count. Naturally you will release this property later, may be in <code>dealloc</code>. So now you are owner of this object 2 times. To match the first ownership via <code>alloc</code> you release in the 3rd line. </p> <p>Now see what happens if you do this in one line:</p> <pre><code>self.obj = [[MyClass alloc] init]; </code></pre> <p>You have gained ownership here two times, one through alloc and one through retain property. So you need to write <code>[obj release]</code> twice. Otherwise you will have a memory leak. But releasing twice is confusing and easier to create bug and you should never do this. Or you need to autorelease this in the same line which is also confusing. </p> <p>So the summary is if you have retain property, then write three lines of code to handle with double ownership. </p> <p>Sorry, can't help with other parts.</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.
    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