Lolloz89
Lolloz89

Reputation: 2809

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

Upvotes: 1

Views: 1730

Answers (2)

bbum
bbum

Reputation: 162712

Might you have zombie detection turned on?

Zombie detection causes nothing to be deallocated, but -- likely -- the retain count will drop to zero and, more usefully, you'll see a one to one correspondence between retain causing and release causing events.


Also, if you don't turn on "only track live allocations", then you'll see the object in Instruments after it is deallocated, with a 0 retain count, but it is really deallocated.

Upvotes: 6

Rui Peres
Rui Peres

Reputation: 25907

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

Upvotes: 1

Related Questions