A C# destuctor is not like a C++ destructor. It is actually an override for Finalize(). This is called when the garbage collector discovers that the object is unreachable. Finalize() is called before any memory is reclaimed.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
Constructor or destructor inheritance is explicit.. Public Extended : base()à this is called the constructor initializer.
Create Date
:
Tuesday, May 13, 2008
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
Like a Java Virtual Machine, the CLR removes the burden of memory management from developers by destroying objects once they are no longer being referenced. Before an object is removed from memory, it must free any resources it has allocated during its lifetime. In C++, this "cleanup code" is usually housed in an object's destructor, whereas in VB it is placed in the Class Terminate () method. Under the .NET Framework, cleanup code must reside in an object's Finalize () method, which is called just before the object is garbage-collected by the CLR. Finalize () is a method in the System.Object class from which all other .NET classes derive. You only have to override this method when you have cleanup code that should be performed before the class is destroyed. For performance reasons, the Finalize () method should only be employed when efficiently freeing a particular resource is a prime concern.
Create Date
:
Saturday, May 10, 2008
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
In order to understand the "finalize" method one needs to understand the concept of garbage collection. The job of freeing up the memory allocated to objects is that of a garbage collector. When the garbage collector determines that an object is no longer referenced it automatically runs a special destructor function called "Finalize". However we have no way to determine when the garbage collector will call the Finalize method. We can only be sure that it will be called at some time after the last reference to the object is released. Finalize is a protected method i.e. it can be called from the class or derived classes however it cannot be called from outside of the class. If a class has a Finalize method it should explicitly call the Finalize of its base class as well. Overrides Protected Sub Finalize () 'Cleanup code goes here BaseClass.Finalize End Sub
Create Date
:
Saturday, May 10, 2008
Click here
to improve the Interview Question, Answer and other fields.
|
|
Inappropriate
|
See Answer
To Email:
Subject:
Note to go along with the question: (Optional, no
more than 1,000 characters)
It is a process during exception handling when the destructor is called for all local objects between the place where the exception was thrown and where it is caught.
Create Date
:
Sunday, April 27, 2008
Click here
to improve the Interview Question, Answer and other fields.