Re: NSMutableDictionary not sending release message to contained objects at dealloc time
Re: NSMutableDictionary not sending release message to contained objects at dealloc time
- Subject: Re: NSMutableDictionary not sending release message to contained objects at dealloc time
- From: Greg Hurrell <email@hidden>
- Date: Sat, 12 Apr 2003 14:22:47 +0930
El Saturday, 12 Apr, 2003, a las 11:49 Australia/Adelaide, mmalcolm
crawford escribis:
Yet while array sends a release when objects are removed, the dict
only sends a release when it itself is deallocated (according to you,
and I defer to your experience on this one!)
Umm, no, it doesn't, and Greg didn't say that.
Yeah, well... I thought he did, because if you look at what he wrote
you'll notice he says nothing about objects being sent a release upon
removal from a dictionary:
The contents of the dictionary should be sent a release message when
the dictionary itself is _dealloced_, to balance the retain message
they are sent when added to the dictionary. If you retain the
dictionary 10 times, it doesn't retain each object inside the
dictionary 10 times - those objects were retained _once_ when they
were added to the dictionary in the first place.
(Yes, which is exactly as the Cocoa docs say.) Greg goes on to write:
If you then release the dictionary 10 times, each object inside the
dictionary is unaffected. It is only when the dictionary itself is
deallocated (retain count goes to zero) that it is emptied and every
object inside it receives a single release.
But what you seem to be telling me, and what common sense tells me, and
what Greg probably meant to tell me, and what Phil Kelley has
demonstrated on the list, and all are in agreement is that:
- objects added to a dictionary are sent a retain (as per the Cocoa
docs);
- objects removed from a dictionary are sent a release (to balance the
retain, although this does not appear in the Cocoa docs, even though I
can find a corresponding comment with respect to NSMutableArray);
- if any objects are still in the dictionary at the time it is
deallocated, then any remaining objects are sent a release message;
Cheers
Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.