Solved

Using Close, Dispose and Nothing

Posted on 2008-06-12
4
611 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:Sanmarie
  • 2
  • 2
4 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 21773466
Close() will be enough, Dispose() will call close anyway.
If you plan to use the connection variable again, then use Nothing, if not, then it is not needed.
GC.Collect() will not collect when you want, the .net environment will decide the proper time.
0
 

Author Comment

by:Sanmarie
ID: 21773843
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
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 21773934
GC.Collect() is not commonly used, there are several discussions about that in Intenet you can google.
0
 

Author Comment

by:Sanmarie
ID: 21774077
Ok. Fair enough. Thanks

San
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now