• 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: Chris Suter <email@hidden>
  • Date: Mon, 6 Aug 2007 17:30:19 +1000


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

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: John Stiles <email@hidden>
References: 
 >Re: dealloc for cleanup versus freeing memory (From: Kurt Bigler <email@hidden>)

  • Prev by Date: Re: offtopic: best way of plainng overall structure of programs/functions etc.
  • Next by Date: Cocoa callback handling
  • Previous by thread: Re: dealloc for cleanup versus freeing memory
  • Next by thread: Re: dealloc for cleanup versus freeing memory
  • Index(es):
    • Date
    • Thread