1. Back To Blog

.NET interview questions: - Explain the steps to clean unmanaged objects and also maintain its performance?

.NET interview questions: - Explain the steps to clean unmanaged objects and also maintain its performance?

In order to clean unmanaged objects we need to follow the below steps:-

• Implement IDisposable interface and implement the dispose function.

• In Dispose function call the "GC.SuppressFinalize" method.

• At the client side ensure that the "Dispose" function is called when the object is no more required.

Below goes the code, this is also called as "Finalize and Dispose pattern". This ensures that your objects are created in Generation 0 rather than Generation 1. "GC.SuppressFinalize" tells the garbage collector to not worry about destructor and destroy the objects in the first call itself.

class clsMyClass : IDisposableclsMyClass()// In case the client forgets to call// Dispose , destructor will be invoked forDispose(false);}protected virtual void Dispose(bool disposing)if (disposing)// Free managed objects.}// Free unmanaged objects}public void Dispose()Dispose(true);// Ensure that the destructor is not calledGC.SuppressFinalize(this);}}

Also view following video on estimations of software projects using Function Point Analysis: -





Get more Dotnet interview questions and answers  for preparation.

Regards,

View author's blog for more Most asked .NET interview questions

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social