title: Objective - C - NSMutableAttributedString Leak
body: <p>I am a newbie to Obj-C, and am experimenting with few things. 
  I stumbled upon one leak issue and would like to know the logical reason behind it.</p>
  
  <p>The following piece of code <strong>leaks</strong> :</p>
  
  <pre><code>(textViewAttrStr is an instance variable of type NSMutableAttributedString)
  
  -(void) init:(NSString*)str
  {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  
  textViewAttrStr = [[NSMutableAttributedString alloc] initWithString:@"Hello "];
  NSMutableAttributedString *part1String = [[NSMutableAttributedString alloc] initWithString:str];
  [textViewAttrStr appendAttributedString:part1String];
  NSMutableAttributedString *part2String = [[NSMutableAttributedString alloc] initWithString:@"!!!"];
  [textViewAttrStr appendAttributedString:part2String];
  [textViewAttrStr retain];
  
  [part1String release];
  [part2String release];
  
  [pool drain];
  }
  
  -(void) dealloc
  {
  if(textViewAttrStr != nil)
  {
      [textViewAttrStr release];
  }
  
  [super dealloc];
  }
  </code></pre>
  
  <p>while the following code <strong>does not leak</strong> :</p>
  
  <pre><code>-(void) init:(NSString*)str
  {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  
  NSMutableAttributedString* tvas = [[NSMutableAttributedString alloc] initWithString:@"Hello "];
  NSMutableAttributedString *part1String = [[NSMutableAttributedString alloc] initWithString:str];
  [tvas appendAttributedString:part1String];
  NSMutableAttributedString *part2String = [[NSMutableAttributedString alloc] initWithString:@"!!!"];
  [tvas appendAttributedString:part2String];
  
  textViewAttrStr = tvas;
  [textViewAttrStr retain];
  
  [part1String release];
  [part2String release];
  [tvas release];
  
  [pool drain];
  }
  
  -(void) dealloc
  {
  if(textViewAttrStr != nil)
  {
      [textViewAttrStr release];
  }
  
  [super dealloc];
  }
  </code></pre>
  
  <p>Can somebody explain why?</p>