Describe ways of cleaning up objects.

Answer Posted / vaidyanathan

By Dispose() method the object is marked for garbage
collection. But user can define a Dispose() method
identified by GC, only when the user implements the
IDisposable interface in the class. Once the dispose()
marks the object for deletion, the garbage collector, in
its subsequent collection cycle, collects the objects by
calling the respective Finalize() methods. So there is no
need for the user to write the Finalize() method. This is
the normal Process of Garbage collection.

At extreme cases user can force the garbage collection at a
specific time by calling GC.Collect() method. This should
be followed by GC.SuppressFinalize() method call to avoid
GC from calling Finalize() method on the same object once
again.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is everything an object c#?

491


What is a method signature in c#?

508


Write a sample code to write the contents to text file in c#?

479


Is class reference type c#?

530


What is a Command Object in C#?

552






Is string nullable c#?

493


Can I call a virtual method from a constructor/destructor?

479


What is the default value of decimal in c#?

488


Is null or empty in c#?

541


Which debugging tools you can use in the .NET ssSDK?

544


How to properly clean up excel interop objects?

500


Write a console application and implement the ternary operator to decide whether the age a user entered after being prompted is allowed to vote or not(given that only citizens between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical input.

1895


How does dependency injection work c#?

496


Define parsing? Explain how to parse a datetime string?

503


What is dll hell, and how does .net solve it?

533