Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a slight inaccuracy with the current Apple doc on Advanced Memory Management?

Apple's Advanced Memory Management doc is pretty well written and precise, but I wonder for its diagram it has:

(mine is the current revision 2011-09-28)

enter image description here

In the diagram, after the alloc and init, the reference count (or the retain count) is 1, which is the basic memory management rule. After the retain, the reference count is now 2. And then Class C sends a copy message to the object, and after that, the object still has a reference count of 2. The new object has a reference count of 1.

So far this conforms to the rules, but next, on the top of the diagram, Class A sends a release message to the object, and the reference count should be a 1? The diagram has a 2 instead. Then Class B also sends a release message to the object, and the reference count now should be 0. The diagram shows a 1 instead. Is this correct, or maybe there is a different way to read the diagram, or maybe some concept is not correct above?

like image 486
Jeremy L Avatar asked Oct 07 '22 20:10

Jeremy L


1 Answers

I think the diagram is a little misleading in two ways. One is that for the alloc and retain steps, the associated counts are what happens as a result of the operation. At the release steps, however, the counts appear to be the state before the operation. That's all that makes sense to me because there is no "Destroyed" method to cause a 1-to-0 transition.

The other misleading part is, I don't think the retain count ever truly goes to zero and I've seen people get confused by believing that it does.

like image 140
Phillip Mills Avatar answered Oct 12 '22 10:10

Phillip Mills