Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rather than sending <code>-release</code> to the object returned by the property accessor method, set the property itself to <code>nil</code>:</p> <pre><code>- (void)dealloc { self.recorder = nil; [super dealloc]; } </code></pre> <p>The compiler will know to do the right thing because you've specified the storage semantics in the property declaration. Synthesizing a property declared with <code>retain</code> semantics is effectively equivalent to writing the following accessor methods:</p> <pre><code>- (AVAudioRecorder *)recorder { return recorder; } - (void)setRecorder:(AVAudioRecorder *)newRecorder { [newRecorder retain]; [recorder release]; recorder = newRecorder; } </code></pre> <p>When you write <code>self.recorder = nil</code>, the compiler translates it into <code>[self setRecorder:nil]</code>. Setting a property to <code>nil</code> in this way therefore avoids both memory leaks and dangling pointers, involves less boilerplate on your part, and more clearly expresses the intent of the code.</p> <p>Finally, it never hurts to re-read <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html" rel="nofollow" title="Apple Developer Library: The Objective-C Programming Language">The Objective-C Programming Language</a>, which has a section on declared properties; and <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html#//apple_ref/doc/uid/10000011i" rel="nofollow" title="Apple Developer Library: Advanced Memory Management Programming Guide">Advanced Memory Management Programming Guide</a>, which goes over all the different approaches to memory management in detail.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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