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

Can you access a hidden base class method in the derived class?

506


Why do I get a security exception when I try to run my c# app?

552


why delegate is type safe?

2603


Why singleton class is sealed in c#?

515


How many constructors can a class have c#?

474






Are arraylist faster or arrays?

493


What is the difference between a variable and a literal?

541


What are annotations in c#?

525


What is the difference between abstraction and encapsulation in c#?

499


From a versioning perspective, what are the drawbacks of extending an interface as opposed to extending a class?

517


What is a view? What is the use of it?

587


What is string [] args in c#?

547


Where is the main method in c#?

530


What is the base class from which all value types are derived?

503


What are types in c#?

498