What is the difference between these statements
obj=null and obj.dispose()

Answer Posted / kishoreg

This is not a good and safe practice to call a Dispose.
In "Dot Net" it is automatically handle by Garbage
collection. It is the responsibility of GC to call the
Dispose and clear the memory.. but it is not sure that when
GC will call the Dispose.

so in that case we can forcefuly call it.

Consider one case when we forcefully destroy the object and
after some time i will try to use the same object at that
time u will get the error msg.

so better to object = null;

other material:
http://blogs.msdn.com/irenak/archive/2006/10/05/SYSK-
212_3A00_--Does-.NET-Garbage-Collector-call-Dispose_3F00_--
Dispose-_1320_-Best-Practices_2E00_.aspx

Is This Answer Correct ?    4 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is concurrent queue thread safe?

692


What is a int in c#?

693


What is private in c#?

674


What is the delegate in c#?

686


What is c# most used for?

771


What is an icollection in c#?

676


Explain how do I get deterministic finalization in c#?

692


Can fields inside a class be virtual?

740


What is thread and explain states of a thread in c#?

661


What are the different types of classes?

714


What is difference between private and protected in c#?

674


Explain publishers and subscribers in events.

735


What is msil, and why should developers need an appreciation of it if at all?

822


What is the difference between User controls and Custom Controls?

806


My switch statement works differently! Why?

704