Re: NSMutableDictionary Memory Question
Re: NSMutableDictionary Memory Question
- Subject: Re: NSMutableDictionary Memory Question
- From: Andy Lee <email@hidden>
- Date: Fri, 23 Mar 2007 14:04:18 -0400
You don't set out to kill objects, if by "kill" you mean deallocate
memory. You balance their retains and their releases, and let the
frameworks do the rest. When an object's retain count drops to 0, it
will be deallocated. If it follows the memory rules, it will release
its subobjects when deallocated.
On Mar 23, 2007, at 1:34 PM, Matt wrote:
So I have a simple question that relates back to basic Cocoa memory
management. I have a dictionary with a few other dictionaries as
keys as well as a few nsnumbers. When deallocating my object that
contains this structure, I'm a bit confused on how to successfully
"kill" all retained objects. :)
If I have a mutabledictionary with other mutabledictionaries as
keys and send the top-level dic a -removeAllObjects method, and
therefore the lower-level dictionaries are giving a release
message, do those in turn pass that release message onto their
objects?
Only if, in being released, they reach a retain count of zero and
therefore are deallocated. Otherwise, no.
If you want to break apart the entire tree, you'll have to iterate
through yourself and remove elements from the collections they belong
to. Then let the memory management take care of deallocating as
appropriate.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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