Interviews4 answers
4 Answers
Dispose:- Dispose method belongs to IDisposable interface. If you want to release unmanaged objects then it is the best to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it's the responsibility of the client to call the Dispose method to do the cleanup.
More important .NET Questions And Answers
Dispose:- Dispose method belongs to IDisposable interface. If you want to release unmanaged objects then it is the best to implement IDisposable and override the Dispose method of IDisposable interface. Now once your class has exposed the Dispose method it's the responsibility of the client to call the Dispose method to do the cleanup
Finalie() method will be called by the runtime. i.e, Garbage collector will take the responsiblity to deallocate the memory for the specific object. But the problem is we can not assume when it will be deallocated. For that, .NET framework supports Dispose(), by using this when ever you think, the object no longer needed, as soon as possible you have to specify objname.dispose(). in u r code.
One more question may be raised in this topic, how to destroy the object of com component in u r .NET application. because CLR does not take the responsiblity to deallocate the objects for unmanaged code. To do this,
System.Runtime.InteropServices namespace provides one class named Marshal.ReleaseComObject(object name)
By using this we can deallocate the memory for com componet in .NEt application.