• 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: releasing an object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >releasing an object (From: Nick Rogers <email@hidden>)
 >Re: releasing an object (From: Graham Cox <email@hidden>)
 >Re: releasing an object (From: Nick Rogers <email@hidden>)
 >Re: releasing an object (From: Shawn Erickson <email@hidden>)

  • Prev by Date: Re: real verses Virtual memory
  • Next by Date: Re: using QLPreviewPanel and supporting 10.5
  • Previous by thread: Re: releasing an object
  • Next by thread: Removing an Object with A Certain Title from an NSTreeController.
  • Index(es):
    • Date
    • Thread