• 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: How to implement an array of dicts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to implement an array of dicts


  • Subject: Re: How to implement an array of dicts
  • From: mmalc crawford <email@hidden>
  • Date: Thu, 20 Dec 2007 17:08:34 -0800


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.



Lastly, it's not clear why you have a finalize method -- it is not used unless you're using garbage collection.


mmalc

_______________________________________________

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


  • Follow-Ups:
    • Re: How to implement an array of dicts
      • From: Jack Hayward <email@hidden>
References: 
 >Re: How to implement an array of dicts (From: Jack Hayward <email@hidden>)

  • Prev by Date: Re: NSTextField Size
  • Next by Date: Re: How to implement an array of dicts
  • Previous by thread: Re: How to implement an array of dicts
  • Next by thread: Re: How to implement an array of dicts
  • Index(es):
    • Date
    • Thread