Re: Class Instantiation Question




"Karl E. Peterson" <karl@xxxxxxxx> wrote

If a class is instantiated at the function level, will the class be
disposed of when execution of the function ends?

<chuckle>

The correct answer is, "nobody knows."

Is that the correct answer? I would have thought the correct answer
would be no, if the system has to clean it up it will be finalized:


[ Excerpt from http://msdn.microsoft.com/msdnmag/issues/1100/gci/ ]

On the surface, finalization seems pretty straightforward: you create an object and when the object is collected, the object's
Finalize method is called. But there is more to finalization than this.
When an application creates a new object, the new operator allocates the memory from the heap. If the object's type contains a
Finalize method, then a pointer to the object is placed on the finalization queue.

[ ... During finalization ...]
The garbage collector scans the finalization queue looking for pointers to these objects. When a pointer is found, the pointer
is removed from the finalization queue and appended to the freachable queue (pronounced "F-reachable"). The freachable queue is
another internal data structure controlled by the garbage collector. Each pointer in the freachable queue identifies an object
that is ready to have its Finalize method called.


LFS


.



Relevant Pages

  • Re: Finalize Queue (WinDBG / SOS)
    ... If an object is in the finalization queue and its finalize bit is ON, ... > public BadClass() ... > class GoodClass: IDisposable ...
    (microsoft.public.dotnet.framework)
  • Re: DataSet and GC.SuppressFinalize
    ... > that we have to call Dispose method, ... But MBVC has it. ... GC.SupressFinalizewill remove the object from the finalization queue. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataSet and GC.SuppressFinalize
    ... > that we have to call Dispose method, ... But MBVC has it. ... GC.SupressFinalizewill remove the object from the finalization queue. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: portable finalizer
    ... finalization in SBCL, but I want to make my code portable. ... is a pointer to a C structure. ... so there is a destroy method: ... object destroyed when it is garbage collected. ...
    (comp.lang.lisp)
  • Re: memory management and productivity
    ... > Doesn't the automatic finalization of an access to a controlled ... But writing Finalize so that it is okay to call it multiple times is ... and doesn't complain if given a null pointer as an argument. ...
    (comp.lang.ada)