5
Reply

What is the use of DISPOSE method?

purosotam gupta

purosotam gupta

10y
7.6k
0
Reply

    it is used for cleaning up the unmanaged objects

    the dispose method is used to release Unmanaged resourse and to clean up object

    Using Dispose method of IDisposable interface we can eliminate need of calling Garbage collector for more than one time . When you call Dispose method CLR will give instruction to the operating system which deletes un-managed object which is internally pointed by the managed object . Once CLR gives instruction to the operating system for deleting un-managed object , immediately CLR deletes managed object . For more details you can see what is the use of dispose method in c# in skillgun.com which contains too frequently asked c# interview questions and answers

    The Dispose method performs all object cleanup, so the garbage collector no longer needs to call the objects' Object.Finalize override. Therefore, the call to the SuppressFinalize method prevents the garbage collector from running the finalizer. If the type has no finalizer, the call to GC.SuppressFinalize has no effect. Note that the actual work of releasing unmanaged resources is performed by the second overload of the Dispose method.

    http://www.dotnet-tricks.com/Tutorial/netframework/P1MK271013-Difference-Between-Finalize-and-Dispose-Method.html