title: objective-c over-releasing in dealloc
body: <p>Is mystring over-released?</p>
  
  <pre><code>-(void)dealloc {
      [mystring release];
      [mystring release];
      [super dealloc];
  }
  </code></pre>
  
  <p>I assume this will not based on [nil release] does nothing:</p>
  
  <pre><code>-(void)dealloc {
      [mystring release];
      mystring = nil;
      [mystring release];
      [super dealloc];
  }
  </code></pre>
  
  <p>-EDIT-
  Let's say I allocate mystring in init and release it in doSomething:</p>
  
  <pre><code>-(id)init {
      if (self = [super init]) {
          mystring = [[NSString string] retain];
      }
      return self;
  }
  -(void)doSomething {
      [mystring release]; // for some good reason
      // ...etc
  }
  </code></pre>
  
  <p>Now to avoid over-releasing in dealloc based on my example above do I have to explicitly do this in the doSomething method?</p>
  
  <pre><code>-(void)doSomething {
      [mystring release];
      mystring = nil; // &lt;- is this mandatory to avoid over-releasing in dealloc?
  }
  </code></pre>
  
  <p>The big question is do I have to explicitly set it to nil when I release it somewhere else in the class to avoid over-releasing in dealloc?</p>
  
  <p>So could I do as many releases as I want in dealloc based if I explicitly set to nil in doSomething?</p>
  
  <pre><code>-(void)dealloc {
      [mystring release];
      [mystring release]; // &lt;- does nothing because mystring explicitly nil?
  }
  </code></pre>