title: NSMutableArray property - Release children
body: <p>Here is what I see when I run the following code:</p>
  
  <pre><code>// Dealloc on MyClass not called
  MyClass* c = [MyClass new];
  self.a = [NSMutableArray new];
  [self.a addObject:c];
  [c release];
  [a release];
  
  // Dealloc on MyClass called
  MyClass* c2 = [MyClass new];
  NSMutableArray* a2 = [NSMutableArray new];
  [a2 addObject:c2];
  [c2 release];
  [a2 release];
  
  // Dealloc on MyClass called
  MyClass* c3 = [MyClass new];
  a = [NSMutableArray new];
  [a addObject:c3];
  [c3 release];
  [a release];
  </code></pre>
  
  <p>Why does dealloc not get called in the first example?</p>
  
  <p>EDIT:</p>
  
  <p>I think I was misunderstanding all this.  Basically what I need to do is:</p>
  
  <pre><code>NSMutableArray* alocal = [NSMutableArray new]; // alocal has a retain count of 1
  self.a = alocal; // a has a retain count of 1
  [alocal release]; // alocal has a retain count of 0
  [a release]; // a has a retain count of 0
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>self.a = [[NSMutableArray new] autorelease]; // a has a retain count of 2
  [a release]; // a has a retain count of 0
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>self.a = [NSMutableArray array]; // a has a retain count of 2
  [a release]; // a has a retain count of 0
  </code></pre>
  
  <p>Just as a note, with the autorelease/array options (#2 and #3), a does not get released right away, so if you want more control go with option #1.</p>
  
  <p>Thanks!</p>