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

Differentiate between dataset and datareader?

713


What is windows form in c#?

727


How do I type a whitespace character?

720


Which .gang of four. Design pattern is shown below?

654


Why delegate is used in c#?

647


In .NET which is the smallest unit of execution?

808


How do I declare inout arguments in c#?

713


Explain About stateless and state full web service

737


What is a bool in c#?

635


How is exception handling implemented in c#?

764


What do you mean by streamreader/streamwriter class in c#?

697


What are generics in c#.net?

775


What is lazy loading and eager loading in c#?

657


Explain the functionalities of satellite assembly?

722


What is datetime parse in c#?

685