Re: dealloc for cleanup versus freeing memory
Re: dealloc for cleanup versus freeing memory
- Subject: Re: dealloc for cleanup versus freeing memory
- From: Kurt Bigler <email@hidden>
- Date: Mon, 06 Aug 2007 00:02:43 -0700
- Thread-topic: dealloc for cleanup versus freeing memory
Yea, I've poured through a lot of that doc at various times. If you had
anything else more specific in mind, please advise, since the real
information in Cocoa documentation often doesn't reveal itself without much
delay. ;)
However, based on an off-list response, I may just need to take over the
process of closing windows prior to quit, so that Cocoa can not do its Quit
"optimization" in relation to closing windows, which may be what is burning
me. So I'll try that first and report back.
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.
Thanks.
-Kurt
on 8/5/07 8:16 PM, Seth Pellegrino <email@hidden> wrote:
> Kurt,
>
> You might be interested in < http://developer.apple.com/documentation/
> Cocoa/Conceptual/AppArchitecture/index.html#//apple_ref/doc/uid/
> 10000005i >.
>
> Good luck!
>
> Seth
>
> On Aug 5, 2007, at 4:03 PM, Kurt Bigler wrote:
>
>> There has been discussion on this list in the past relating to
>> dealloc on
>> quit. For example in the thread "which cocoa objects to dealloc ?":
>>
>>
>> on 3/18/06 2:40 AM, j o a r <email@hidden> wrote:
>>
>>> Cocoa will skip over sending deallocation messages to objects when
>>> your app is about to quit. This is an optimization,
>>
>>
>> My basic design problem is that coming from C++ experience I am
>> used to
>> using the equivalent of dealloc (the destructor) for all cleanup
>> purposes,
>> whether they pertain to releasing memory or not. In short it is
>> typical in
>> C++ that all types of of resource cleanup are taken care of via the
>> same
>> "method" that releases memory. Such resource cleanup may include
>> posting
>> files, communicating with other applications, and dealing with other
>> external resources that are not managed by the OS automatically.
>>
>> So it may sound like a nice idea that Cocoa optimizes memory
>> release on
>> quit, but if this means dealloc is not called it means I have not
>> done all
>> the other non-memory related cleanup that I would typically do in
>> dealloc.
>> I'm not aware of any other generic place to put such cleanup actions,
>> besides dealloc, so please inform me if I'm missing something.
>>
>> My specific problem is typical of the kinds of things I saw
>> reported in
>> several threads on this list: My custom view is not reliably
>> getting a
>> dealloc message on quit.
>>
>> To make it more mysterious, the view gets a dealloc if the Command-Q
>> shortcut is used to quit, but not if Quit is selcted from the menu
>> using the
>> mouse. If anyone has any clues why this might be, I'd appreciate it.
>>
>> I also notice that my window delegate never receives a dealloc,
>> even when
>> the window is closed explicitly, i.e. via the close button rather than
>> implicitly due to Quit. (In the close-button case, my custom view
>> *does*
>> receive a dealloc message.)
>>
>> Thanks for any info.
>>
>> -Kurt Bigler
>>
>>
>>
>> _______________________________________________
>>
>> 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
>
>
_______________________________________________
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