Solved

disposing database objects

Posted on 2012-03-27
4
223 Views
Last Modified: 2012-03-27
Greetings,



After reading, inserting, deleting items in an Access database using ADO, I always close the connection, but do not dispose of the objects or set any of them to nothing.  I do not seem to have any problems but need some opinions,  (examples if applicable) as to whether or not this is a good practice. I am using vb through vs 2008.

Thanks
0
Comment
Question by:VWhitehead
  • 2
4 Comments
 
LVL 9

Expert Comment

by:armchair_scouse
ID: 37772198
I understand there is something called the 'Garbage Collector' built-in to .Net that disposes of unused objects, but IMHO it is always good programming practice to dispose of unused objects if you have instantiated them.  I believe you can also call the garbage collector directly (GC.Collect?!?) but I would bow to someone with greater knowledge of .Net on that point.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 500 total points
ID: 37772290
It is good practice to get used to disposing of objects as soon as you are finished with them as garbage collection is non-deterministic (meaning it is unknown when it will clean up your unused objects).
The best way to ensure good disposal is the use of the using statement as the object is automatically disposed of at the end using.

Using cn as New SqlConnection(myConnectionString)
   ----
   ----
End Using
0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 37772305
0
 

Author Closing Comment

by:VWhitehead
ID: 37772490
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL LINE CONTINUATION ISSUE 12 37
Winform Module - What is the ASP.Net equiv 2 28
vb.net 1 month apart 11 35
VB.Net - String Manipulation Scenario 2 23
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…

790 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