• 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: WeakHashMap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WeakHashMap


  • Subject: Re: WeakHashMap
  • From: Pierre Bernard <email@hidden>
  • Date: Sun, 28 Aug 2005 09:56:25 +0200

Hi!

thanks for your reply.

In the end I went for something completely different. Namely a class category as described here: http://www.cocoadev.com/index.pl? ClassCategories

Deallocation happens in the swizzled dealloc method. My original business object code is not polluted by view code, even though at runtime, the object is.

Pierre

On Aug 28, 2005, at 9:05 AM, Michel Schinz wrote:

Le 22 août 05 à 15:09, Pierre Bernard a écrit :


Now I don't want to leak memory. I would like the view to go away if the NSManagedObject is deleted. here the Java programme in me longs for a WeakHashMap, where entries go away when their key does. No such luck in absence of a garbage collector.


One idea could be to do the garbage collection yourself. That is, you periodically walk over all the entries of your dictionary, look at the retain count of the business object represented by the key (using the "retainCount" method), and if it is equal to one, you know that you have the only reference to it. You therefore remove it from the dictionary, which should release and de-allocate it.


This only works if you are sure that any object belongs to at most one such weak dictionary. If it isn't the case, you need to do some additional work.

Michel.



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >WaekHashMap (From: Pierre Bernard <email@hidden>)
 >Re: WaekHashMap (From: Michel Schinz <email@hidden>)

  • Prev by Date: Re: WaekHashMap
  • Next by Date: Obj-C++: instantiating C++ type ivar within an obj-c class
  • Previous by thread: Re: WaekHashMap
  • Next by thread: Clearing NSTableView on unbind
  • Index(es):
    • Date
    • Thread