Alternative to NSZombie

I am trying to debug the loss of EXC_BAD_ACCESS using NSZombie. My application creates many large objects, although they are not freed up with NSZombie support, which causes the application to crash in seconds. This means that I cannot even crash EXC_BAD_ACCESS before the application crashes due to low memory.

Is there an alternative? Is it possible to include NSZombie in a specific file instead of the entire project? How else can I debug this failure (I know that this is caused by UIGestureRecognizer, but I use a lot of them, so it does not narrow down the problem significantly).

Thanks.

Edit: Thanks for the tip. I think I may have solved the problem and will report after more rigorous testing.

Edit 2: A collaborative question myself, but chose an answer that seems to be a good solution to any such problems in the future.

+5
source share
2 answers

All I can think of is to implement it manually; create a mediation container that contains an object of type id and assigns it as -forwardingTargetForSelector: and also receives a response to -isKindOfClass: etc.

Disable ARC for the proxy server and save it during init and check its own retainCount when assigning the forwarding destination.

If the counter is 1, then raise an exception or write a warning or something else.

If suspicious classes terminate themselves and return the proxy server as the last line of their device.

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

+2
source

NSZombies was / was designed for applications that use their own memory management. If your application uses ARC, this will not help.

Create a new breakpoint: all exceptions

This usually shows you where you are causing poor access.

-3
source

Source: https://habr.com/ru/post/1206102/


All Articles