• 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: dealloc for cleanup versus freeing memory
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dealloc for cleanup versus freeing memory


  • Subject: Re: dealloc for cleanup versus freeing memory
  • From: John Stiles <email@hidden>
  • Date: Mon, 6 Aug 2007 11:07:42 -0700

I feel as if you remove all the benefits of reference counting if you add a specific "cleanup" method. If some other method had retained the object for some reason, what is it supposed to do now?
Explicit cleanup mechanisms only seem to work if you want an object that can't be copied or shared at all, and you give up all the benefits of refcounting for what don't appear to be very solid benefits (basically, things "work better" even if you accidentally leak an object).



On Aug 6, 2007, at 12:30 AM, Chris Suter wrote:


On 06/08/2007, at 5:02 PM, Kurt Bigler wrote:

Still the notion that Cocoa interprets dealloc literally to deal with memory
allocation only is disturbing to me. My experience leads me to believe that
functional tear-down is primary and that memory deallocation is secondary
but intimately intertwined with tear-down. This is the basis for the C++
destructor chain which has its closest Objective-C analogy in the dealloc
message. And dealloc is the only standard method (present in the root
class) that could conceivably be used for tear-down. I know that NextStep
and Cocoa have been around for a while, but the notion of Cocoa
optimizing-out dealloc almost seems like shooting a time-honored design
pattern in the foot. I'd appreciate any reflections on this.

I'd argue that the same ideas apply to other languages as well as Objective C. I personally don't believe in doing anything substantive in dealloc methods. There's no way of reporting an error back and if you use reference counting or garbage collection it becomes tricky to know when the method gets called. It's much better in my opinion to call the clean up code that must be run from whatever triggers that need. In your case, you should hook into application termination. Obviously you'd make sure that your cleanup is called via the dealloc method if it hadn't already been done.


As to Objective-C not having a dedicated standard method for this kind of thing: why does it need to have a standard name? If there was a standard name, there'd be no way for you to give it a more meaningful name.

- Chris

_______________________________________________

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:
40blizzard.com


This email sent to email@hidden

_______________________________________________

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: dealloc for cleanup versus freeing memory
      • From: Chris Suter <email@hidden>
    • Re: dealloc for cleanup versus freeing memory
      • From: Bill Bumgarner <email@hidden>
References: 
 >Re: dealloc for cleanup versus freeing memory (From: Kurt Bigler <email@hidden>)
 >Re: dealloc for cleanup versus freeing memory (From: Chris Suter <email@hidden>)

  • Prev by Date: Re: How to require contiguous selection in a table view?
  • Next by Date: Re: Writing Mail.app Plugin
  • Previous by thread: Re: dealloc for cleanup versus freeing memory
  • Next by thread: Re: dealloc for cleanup versus freeing memory
  • Index(es):
    • Date
    • Thread