Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode Zombies shows CFArray increasing Live Bytes

I've not used Zombies before, and must admit I'm not that sure what it's doing. However, one thing concerns me:

CFArray seems to be continually increasing its Live Bytes and # Living columns, along with a couple of mallocs, which I presume are related. This is when my app is just sitting there, rendering (OpenGL) and waiting for input.

I've tried running the leaks instrument, and that doesn't show that I'm getting memory leaks during this period, or even any more allocations. No allocations on anything, let alone CFArray.

So which of the two instruments should I believe? Or is it simply that I don't understand what the Zombies instrument is actually doing?

If there's any decent documentation on Zombies that anyone could point me to, that would be cool. Apple's docs seem to gloss over it a bit.

like image 339
Dave Avatar asked Feb 26 '23 05:02

Dave


2 Answers

NSZombies basically replaces deallocated objects with a placeholder to notify the developer if it has been accessed after a dealloc (obviously a bad thing). This helps resolve retain / release issues.

By turning it on, your app is going to appear like it is leaking memory like a sieve because nothing will ever truly be deallocated. Generally, I use NSZombies to look for specific crashers during debugging (or you can turn on Zombies in the Allocations instrument - which should also warn you that memory usage will only go up)... I use Leaks or Allocations w/Heap Shots in instruments to do memory analysis on a functioning app.

Another good question / answer on SO: What is NSZombie?

like image 149
rcw3 Avatar answered Mar 16 '23 10:03

rcw3


enabling zombies sees the objc instances are not freed when their retain count reaches 0 (normally, dealloc would be called at this time and the object's memory would be freed). specifically, dealloc will be called, but the object will not be freed and the ref count will be available for later use.

of course, there's more, and it's an implementation detail: someplace in the messaging system, the system will check that you do not message a zombie (a zombie is an object which has a retain count of 0). if you message a zombie, then the system will detect this for you (as you may have encountered when running with zombies enabled).

like image 45
justin Avatar answered Mar 16 '23 11:03

justin