• 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
NSCache objects not being collected under GC?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSCache objects not being collected under GC?


  • Subject: NSCache objects not being collected under GC?
  • From: Nick Zitzmann <email@hidden>
  • Date: Thu, 18 Aug 2011 20:26:08 -0600

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?)

Nick Zitzmann
<http://www.chronosnet.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: "email@hidden" <email@hidden>
  • Prev by Date: Re: Printing
  • Next by Date: Strange NSFileManager file replacement issue
  • Previous by thread: Re: Printing
  • Next by thread: Re: NSCache objects not being collected under GC?
  • Index(es):
    • Date
    • Thread