• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSCache objects not being collected under GC?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCache objects not being collected under GC?


  • Subject: Re: NSCache objects not being collected under GC?
  • From: "email@hidden" <email@hidden>
  • Date: Fri, 19 Aug 2011 09:40:37 +0100

On 19 Aug 2011, at 03:26, Nick Zitzmann wrote:

> Short version: Have any of you ever used NSCache in a GC-enabled app? If so, then how did you get the garbage collector to collect them?
>
> Long version: I have a framework that is used in a traditional retain-release app and a different GC-enabled app. The framework creates NSCache objects for storage of throw-away objects, and stores these NSCache objects in a CFDictionaryRef. At some point, the CFDictionaryRef is instructed to remove the entire cache when the app no longer needs that cache.
>
> That pops the NSCache and deallocates it in the retain-release app, but in the GC app, I ran an Instruments test and found that the NSCache objects and their contents were never being finalized. If I change the code so the code uses NSMutableDictionary instead of NSCache, then the dictionaries and their objects are properly finalized when popped. I want to use NSCache and not NSMutableDictionary, but I can't do this in the GC-enabled app if the collector is going to let the caches live forever. How do I make it so that the collector collects them?
>
> I already tried using Instruments to monitor the GC object graph, but the results made no sense. According to Instruments, the NSCache objects were rooted by a non-object memory address created before main() was called, a long time before the objects were made. Also, I noticed that objects in the cache would not identify the cache as their root. (Is that normal?)

I don't use NSCache but I have used instruments to effectively debug GC memory collection problems.
The described rooting behaviour of NSCache sounds peculiar to me.

What happens if you call -removeAllObjects. Are the cached objects finalised correctly?
I know this isn't the same as collecting the NSCache instance but at least, as a workaround if the issue persists, you can recycle the NSCache instances.


Regards

Jonathan Mitchell

Developer
Mugginsoft LLP
http://www.mugginsoft.com_______________________________________________

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

  • Follow-Ups:
    • Re: NSCache objects not being collected under GC?
      • From: Nick Zitzmann <email@hidden>
References: 
 >NSCache objects not being collected under GC? (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Strange NSFileManager file replacement issue
  • Next by Date: SKPaymentTransaction has no receiptData property for Mac In App Purchase
  • Previous by thread: NSCache objects not being collected under GC?
  • Next by thread: Re: NSCache objects not being collected under GC?
  • Index(es):
    • Date
    • Thread