收录日期:2020/10/23 11:03:30 时间:2010-09-07 02:30:56 标签:iphone

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.

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 = ...).