Re: How to implement an array of dicts
Re: How to implement an array of dicts
- Subject: Re: How to implement an array of dicts
- From: Jack Hayward <email@hidden>
- Date: Thu, 20 Dec 2007 17:13:14 -0800
On Dec 20, 2007, at Dec 20, 2007 | 5:08 PM, mmalc crawford wrote:
On Dec 20, 2007, at 4:36 PM, Jack Hayward wrote:
I had to retain this data in order to get things to work.
The pointers to these datum are all instance variables.
From my reading of the docs, I should not have to retain, because
the instance variables are referring to them, and the ivars
continue to exist.
No.
*In a managed memory environment*, simply because an object is an
instance variable does not mean it won't go away if you haven't got
the memory management semantics right.
The rules are spelled out here:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
MemoryMgmt/Tasks/MemoryManagementRules.html>
Since you created defaultPreset, defaultPreset2, and presets
without using any methods that conform to the "ownership rule", you
don't own them until you retain them.
Read the rules above to understand why this is fundamentally flawed:
newParm = [[[NSDictionary alloc] initWithObjectsAndKeys:
self.parmName1, @"name",
self.value1, @"val",
self.duration1, @"dur",
nil] retain];
You should also consider the advice given in <http://
developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447-
DontLinkElementID_4> -- use accessor methods to help you get memory
management right.
And in general, do a sanity check against the documentation and
sample code. The documentation generally gets the memory
management right; you shouldn't anywhere in the documentation see
an example like the code above for newParam.
Thanks for all of the above - I will read up.
Lastly, it's not clear why you have a finalize method -- it is not
used unless you're using garbage collection.
The finalize method is supplied as part of the QC-plugin template.
I thought that was where I was supposed to release anything that I
created/retained.
_______________________________________________
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