object.dispose and object = nothing

kenchen

Newcomer
Joined
Apr 9, 2003
Messages
3
Location
Malaysia
hai all,

i'm new to vb.net, and have a simple question for object's lifetime.

what is the difference when set object = nothing or call the object's dispose method ???

BTW, when calling the dispose method, we can pass nothing, true and false to this method.(what difference) as follow

object.dispose()
object.dispose(true)
object.dispose(false)

Please guide me a bit, thank you
 
You should limit yourself to calling the Dispose method, with no arguments, for types that implement the IDisposable interface. Setting an object reference to a null value does not invoke the object's dispose pattern thereby skipping any unmanaged reference clean up, which negates any efforts to produce efficient code.

In other words, for objects that are disposable dispose them and then let the garbage collector do its job. For objects that aren't disposable simple do nothing. The GC will handle them in most cases. There are rare exceptions to this of course which have to be handled on a case-by-case basis.
 
Back
Top