An NSMutableArray that doesn't retain?

Posted by synic on Stack Overflow See other posts from Stack Overflow or by synic
Published on 2010-05-17T15:32:32Z Indexed on 2010/05/17 16:40 UTC
Read the original article Hit count: 94

Filed under:
|

A few UIViewControllers in my app that need to register with a "provider" class in their viewDidLoad methods. I've just been adding them to an NSMutableArray contained in the provider class.

However, I don't want this NSMutableArray to keep them from being dealloc'ed, and I also want to have them remove themselves from the NSMutableArray in their dealloc methods.

I tried just issuing a [self release] after adding them to the array, and this works, but in order to avoid a crash when they get dealloc'ed, I have to issue a [self retain] right before I remove them. It seems like I'm doing something horribly wrong by retaining an object in it's own dealloc method.

Is there a better way to store these values?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c