Search code examples
objective-ciosmemory-leaksinstrumentsreference-counting

Object with reference count equals to 0 is still persistent


I am trying to enhance the memory allocation in my non-ARC app. There are some objects that, even if their reference count are 0, they are listed as persistent object between two heapshot.

This is my heapshot view: enter image description here

Lets take for instance the selected LSBookChapter in the 1st heapshot (0x6deb180). This is the history of that object:

enter image description here

Why that object isn't deallocated? If the reference count is 0 I can't figure out when I over retained that object..


Solution

  • In my previous application, I had some concerns as you are having right now because, I didn't had leaks, but the memory was growing. After some research I stumbled upon this. I did tried to make some shortcuts on his article, but in the end I just read the whole thing to actually understand what was wrong. And YES, I was able to pinpoint every problem I had. And I might say I had quite a few.

    For your particular problem, I didn't do what you are you trying right now: seeing the retainCount of an object in different heapshots. I think it's a waste of time honestly. My main goal is to make sure that if I do something and I reverse it, the memory should not increase or if it does it should be slightly (quick example: going into a new UIViewController and press the button back).