Re: Tracking the retain count
Re: Tracking the retain count
- Subject: Re: Tracking the retain count
- From: Jonathan Hull <email@hidden>
- Date: Tue, 19 May 2015 23:26:31 -0700
> On May 19, 2015, at 8:04 PM, Quincey Morris <email@hidden> wrote:
>
> Solution B: We retain each object as it enters the cache. That allows us to selectively mark objects purgeable by releasing them again. Drawbacks: None.
You still have to be really careful about threading here. How do I know which objects have already been marked as purgeable? What if a new object is added to the cache just after the cache has been asked to purge due to low memory, but before the autorelease pool has drained?
It seems like you would still need to track which objects have been retained on a per-object basis to avoid shooting yourself in the foot. Having a collection with strong references to cached objects just provides this implicitly (and in a very future-proof way), but there are other ways (e.g. bitfields) which might save space if required.
I still like Roland’s suggestion the best: A NSMapTable with strong keys and weak values combined with an array/set with strong references to keep things around (which gets purged in low memory situations). If you are worried about the extra space, limit the cache to the 100 most recent objects (or some other number determined by testing). That memory will be reclaimed in low-memory situations anyway.
Thanks,
Jon
_______________________________________________
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