title: Memory leak in objective-c class init method
body: <p>I'm having problems with a leak in the <code>init</code> method of a class I have created.  To keep it simple, I have the following (simplified) problem:</p>
  
  <ul>
  <li>ViewController initialises an instance of</li>
  <li>ClipData class which initialises an instance of</li>
  <li>AnimationData class which initialise a string</li>
  </ul>
  
  <p>ViewController:</p>
  
  <pre><code>myClipData = [[ClipData alloc] init];
  </code></pre>
  
  <p>ClipData:</p>
  
  <pre><code>- (id)init
  {
      self = [super init];
      if (self) {
          animData = [[AnimationData alloc] init];  //LEAK HERE
      }
  
      return self;
  }
  </code></pre>
  
  <p>AnimationData:</p>
  
  <pre><code>- (id)init
  {
      self = [super init];
      if (self) {
          name = [NSString string];
      }
  
      return self;
  }
  </code></pre>
  
  <p>All the objects in the classes are declared as <code>(nonatomic, retain)</code>.  I'm aware that doing this bumps up the retain count, but how do I initialise the <code>AnimationData</code> without leaking the <code>animData</code>???</p>
  
  <p>Probably a very stupid question, so any help much appreciated. </p>
  
  <p>Thanks,<br>
  Duncs</p>