Deallocating NSMutableArray of custom objects

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-03-17T18:59:57Z Indexed on 2010/03/17 19:01 UTC
Read the original article Hit count: 311

I need help with deallocation of my NSMutableArray of custom objects. I need to retain the array and so I have added a property in .h and I release it in dealloc in .m file. When I add objects to the array, I do the following:

  myarray = [[NSMutableArray alloc] init];
  [myarray addObject:[[mycustomObject alloc]initWithObject:obj1]];
  [myarray addObject:[[mycustomObject alloc]initWithObject:obj2]];

Now, I don't know how to release mycustomobject. If I do the following:

   [myarray addObject:[[[mycustomObject alloc]initWithObject:obj1] autorelease];

I run in to problems when I access the array later. Please advice.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsmutablearray