Re: releasing an object
Re: releasing an object
- Subject: Re: releasing an object
- From: Sherm Pendley <email@hidden>
- Date: Sat, 10 Oct 2009 12:53:52 -0400
On Sat, Oct 10, 2009 at 12:21 PM, Shawn Erickson <email@hidden> wrote:
>
> Anyway the amount of code you have posted leave to much out to understand
> all that may be wrong with your memory management.
The code does show one common anti-pattern - calls to -retain and
-release that should be hidden in an accessor method.
Each instance variable that refers to an object should have a
setVariable: setter method that properly releases the old value and
retains the new value. Encapsulating the memory-management code makes
it far easier to debug - scattering it throughout your code leads to
torn hair and madness.
It's also good OOP; when you find yourself repeating some code around
access to an instance variable, it's often a good idea to factor the
repetitious code into accessor methods. That makes the repeated code
easier to manage, and leaves less clutter in the calling code.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
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