tags:

views:

28

answers:

1

I have an issue where I need to find out what objects are retaining a NSMutableArray. If it is an object I created I can just override retain and release and set a breakpoint on it, but since it is a NSMutableArray I can't. I tried to subclass NSMutableArray but I get exceptions when I try to add to my subclass. Any ideas?

I know you should not really be looking at retain counts but this is complicated code that I inherited and don't know what objects are retaining it.

A: 

Subclassing is definitively your best shot but subclassing class cluster ain't easy. Your exception is probably one of the "blablabl only defined for abstract class".

If you want to go that way, you can embed an instance of NSMutableArray in a custom class and forward every call you actually made to NSMutableArray to the embedded instance.

However, respecting the simple rules of memory management (read apple's doc here) should get you out of this. Be sure you release every owned instance of the array. Owned instance are the one obtained with a method having its name start with "alloc" or "new" or containing "copy".

Be sure you always use property accessor when assigning a object's based property (self.myProperty = ... instead of myPorperty = ...).

VdesmedT
That is a good idea, forwarding to another class. I solved my problem by looking at my retain counts on other objects that held the array. Not as direct but close enough. Also beware of atomic getters that increase the retain count. They are cleaned up eventually but certainly make it harder to do retain count analysis, which I agree should be avoided in most cases.
possen