Search code examples
iosobjective-cmemorynszombie

Alternative to NSZombie


I'm trying to debug an EXC_BAD_ACCESS crash using NSZombie. My app creates lots of large objects though and with NSZombie enabled they aren't getting released causing the app to crash in seconds. This means I can't even cause the EXC_BAD_ACCESS crash before the app crashes due to low memory.

Is there an alternative? Can I enable NSZombie on specific file instead of the entire project? How else could I debug this crash (I know it's caused by UIGestureRecognizer but I use them a lot so it doesn't narrow down the issue significantly).

Thanks.

Edit: Thanks for the advice. I think I may have solved the issue and will report back after more testing.

Edit 2: Sovled the issue myself but selected the answer which seems like it would be a good solution to any similar issues in the future.


Solution

  • All I can think of is implementing it manually; create a proxy container that holds an object of type id and nominates that as -forwardingTargetForSelector: as well as getting it to respond to -isKindOfClass:, etc.

    Disable ARC for the proxy and have it retain itself during init and check its own retainCount when nominating a forwarding target.

    If the count is 1 then raise an exception or log a warning or whatever.

    Have suspect classes wrap themselves in and return a proxy as the last line of their unit.

    For possible bonus points, store [NSThread callStackSymbols] somewhere (probably on disk) during the proxy's unit so you can at least find out where the incorrectly managed object was created.