What is the significance of the “finalize” method ?

October 28, 2007 · Filed Under Placement Questions, VB .Net Interview Questions 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

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

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email