dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pnet-developers] Destructors are not being called - bug or usage er


From: Carl-Adam Brengesjo
Subject: Re: [Pnet-developers] Destructors are not being called - bug or usage error?
Date: Sun, 16 May 2004 23:55:54 +0200
User-agent: Mozilla Thunderbird 0.6 (Windows/20040502)

David Logan <address@hidden> wrote:

OK, technically I can respect that. But in oop-speak, I thought the idea was that code and data were self contained. That statement would mean that a class is responsible for its *own* cleanup. But now, by not requiring destructor calls, the requirement that a class execut its "shutdown code" or "cleanup code" has now been moved to the calling class, hasn't it?

David Logan

I have been taught, at least concerning .NET (M$) that the class/object should not have to clean up it's mess by itself, though it's a good/common programming custom - it's kinda the whole idea with an garbage collector and the C# language, indifferent to (ie.) C/C++ where it's very important to keep track of the memory usage.

At least this is what Microsoft claims. It was one of the topics that were under [heavy] discussion -- on a .NET/C# "propaganda" conference/presentation held by Microsoft I attended half a year ago -- as many C/C++ programmers are, more or less, used to do thier own "dirty work".

The destructors >shall< be called prior exit/memory deallocation by the framework (read Garbage Collector) - but the exact time of when this id done is uncertain.

To quote the MS .NET Class Library -- System.Object.Finalize():

        "This method [Object.Finalize] is automatically called after an
        object becomes inaccessable, unless the object has been
        extempted from finalization by a call to
        System.GC.SupressFinalize. During shutdown of an application
        domain, Finalize is automatically called on objects that are not
        exempt from finalization, even those that are still accessible."

Dunno if it's ontopic, but other types of finalizers, such as Dispose() or Close() will not be called by the framework - but logically these would be called internally by the destructor, if neccesary. (Not sure in the case of System.Windows.Froms close/exit signals etc though).

Carl-Adam Brengesjo


reply via email to

[Prev in Thread] Current Thread [Next in Thread]