Re: WeakHashMap
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