Reputation: 2549
I'm watching a WWDC 2013 video called "Fixing memory Issues"
When the presenter introduces retains, releases and retain cycles. He briefly mentioned that too many releases leads to crashes. I didn't get it. What does too many releases means in this case?
In my understanding, 1 reference count means +1 in ARC for that object, with many things things reference to each other, it may exist some reference that are not used by other codes. Thus leads to leaks. But why too many releases lead to crashes? Is 0 the minimal counting number that an object can go? If so, why will it lead to crashes?
Upvotes: 1
Views: 72
Reputation: 114975
The slide you have shown refers to the manual processes you had to use before Automatic Reference Counting (ARC).
Without ARC the programmer is responsible for calling retain
and release
to manage the reference count on an object.
The reference count is positive, non-zero while the object is still required and 0 when it was no longer required.
If you called release
when the reference count was already 0 then your program was terminated as it indicates you have an error in your code.
Because tracking when an object is no longer required across complex execution flows is difficult, under and over releasing (resulting in leaks and crashes) is common if you don't use ARC
Upvotes: 2