Link to home
Start Free TrialLog in
Avatar of Sanmarie
Sanmarie

asked on

Using Close, Dispose and Nothing

Using .NET 2.0, VS 2005, VB.net

I have a connection object (global scope) and other objects that I want to remove from memory when finished. I call Close, then Dispose then set it to nothing. Is this a good way to clear up the object or is this too much. Also, I call the garbage collector after all of this.

Thanks
San


myOleDbConnection.Close()
myOleDbConnection.Dispose()
myOleDbConnection = Nothing
 
GC.Collect()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Sanmarie
Sanmarie

ASKER

Thanks Jaime_Olivares,

Then what's the purpose of anyone calling GC.Collect() if the garbage collector is going to run on its own time?

San
GC.Collect() is not commonly used, there are several discussions about that in Intenet you can google.
Ok. Fair enough. Thanks

San