Re: resetting ivars safely
Re: resetting ivars safely
- Subject: Re: resetting ivars safely
- From: Erik Buck <email@hidden>
- Date: Thu, 13 Sep 2007 11:31:15 -0700 (PDT)
On 9/13/07, Daniel Child <<email_removed>> wrote:
> Thanks for the suggestion. I did. It is helpful on accessors and the
> basic notion of ownership. ("X created or copied it so X needs to
> release it.") But I don't find that documentation terribly clear on
> some of the scenarios I have been dealing with. My two main scenarios
> requiring attention to memory have been
>
> - reinitializing or resetting instance variables
Implement accessors. Put memory management logic exclusively in accessors. Implement reinitialization by calling the accessors to set instance varaible. Don't touch the instance varaibles directly accept in the accessors.
> - adding objects to a collection, which itself is an instance variable
The collection classes obey Cocoa memory management conventions, so you shouldn't care what the collections do with memory management. If you follow the conventions, you will be fine.
Finally, autoreleased objects are not released or deallocated at random times. They are released when the most nested autorelease pool that contains the objects is itself deallocated. he AppKit manages a top level autorelease pool that is allocated and released by the event loop.
_______________________________________________
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