dispose and nothing? whats the main difference?

G

Guest

greetings,
should i do this

obj.dispose

then

obj = nothing

both does the same thing right? whats the core difference?
 
J

John Saunders

Asha said:
greetings,
should i do this

obj.dispose

then

obj = nothing

both does the same thing right? whats the core difference?

No. obj = nothing doesn't do anything anymore. It simply removes one
reference to the object. If that's the last reference to the object, then
the object may eventually be garbage-collected.

Dispose cleans up whatever the object thinks needs to be cleaned up, and
does it immediately.
 
G

Guest

Dispose method is used to clean up the unwanted resources like sqlconnections,command objects,

dispose method will be called automatically if we create the instance in the following way

using ( DBreader reader=sp.executereader)
{

}

if DBreader is implemented idisposable interface then dispose method will be called
automatically at the end of scope,

nothing is used to remove the reference of the object even if we force the object to nothing, it will take some time to relaese the reference by the garbage.
 
S

Scott Allen

On Tue, 13 Jul 2004 21:37:01 -0700, Saravanan Durai <Saravanan
Dispose method is used to clean up the unwanted resources like sqlconnections,command objects,

dispose method will be called automatically if we create the instance in the following way

using ( DBreader reader=sp.executereader)
{

}

if DBreader is implemented idisposable interface then dispose method will be called
automatically at the end of scope,
In fact, the only objects you can put inside a using clause are
objects implementing IDisposable!

--s
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top