Re: Tracking the retain count
Re: Tracking the retain count
- Subject: Re: Tracking the retain count
- From: Quincey Morris <email@hidden>
- Date: Wed, 20 May 2015 04:17:58 +0000
On May 19, 2015, at 20:37 , Graham Cox <email@hidden> wrote:
>
> I think what the OP says he wants is that the cache can only release when it knows nobody else has a reference to an object as well
My answer on this to Britt is that this is unknowable in general. *That* (or so I claim) is why it’s not safe to reason about retain counts. If Britt could be said to be wrong about anything, I’d say it’s this, the idea that “nobody else has a reference” is a meaningful concept. For all practical purposes it isn’t**.
— It’s unknowable in general. Various parts of the system frameworks may have a need to reference your object for some reason that you don’t know and don’t care about. One sort of trivial example would be when zombies are enabled. In that case, there’s a strong reference to every object ever created. A more practical (though hypothetical) example might be if your object is retained by a NSInvocation that’s already been used for some purpose, but is itself cached somewhere in the frameworks and won’t be purged until some future time you can’t control.
— The state of the memory management system may not be internally consistent at every single moment in time. For example, an object that’s in the process of being freed may for a short while still have an actual retain count of 1 even though there are no strong references to it anywhere. (It’s not the same thing really, but I seem to recall that due to serial nil’ing of weak references in ARC there can be short timing windows during dealloc where a weak reference is still non-nil but the object it refers to is gone. The runtime prevents you from using it, but it still has some very weird consequences. I think this came up on cocoa-dev about a year ago.)
— There may be implementation details that you can’t take into account. What if (hypothetically) there were two different retain counters for every object — say a Cocoa retain count and a CF retain count? What could you then conclude from [someObject retainCount] alone? Nothing at all, really.
** Nor does Britt’s app need it to be. All that’s necessary is that old objects be inaccessible. The existing code ensures that.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden