Click here to hide categories Click here to show left categories

User: Home          welcome : Guest          Log In / Register here     




.NET interview questions: - So how can we clean unmanaged objects and also maintain performance?

We need to follow the below steps:-

  • Implement IDisposable interface and implement the dispose function.
  • In Dispose function calls 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 : IDisposable

    {

        ~clsMyClass()

        {

            // In case the client forgets to call

            // Dispose , destructor will be invoked for

            Dispose(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 called

            GC.SuppressFinalize(this);

        }

    }

In this .NET interview questions we have added a visual studio tips and tricks called “Functionality from refactor menu”.

Scenario: - Many times as a developer you come across functions with lots of input parameters .For various reasons you want to shuffle them, reorder them or remove some of them.

Solution: - It can be easily achieved by using reorder functionality from refactor menu. Following is the video solution for it: -

Helpful Website Url
http://www.questpond.com/
Share this article   |    Print    |    Article read by 4525 times
Author:
Shivprasad koirala Koirala
I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small E-learning company in India. We are very much active in making training videos , writing books and corporate trainings. Do visit my site http://www.questpond.com for .NET, C# , design pattern , WCF , Silverlight , LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server training and Interview questions and answers
Related Articles:
Related Interview Questions: