Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close a DataSet??

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
0
0
US
In the Load function of a form, I create a populate a dataset with data using the following command:

Code:
Me.Lot_DataTableAdapter.Fill(Me.DESDataSet.Lot_Data, SelectLotForm.lotnumber)

I was just wondering what best practice is when closing the form, Should I dispose of the dataset, dataadapter, etc or will they be disposed automatically when the form is closed.

Mighty
 
It should dispose automatically when the form closes.
 
I always set my objects to Nothing once I'm finished with them or in the Finally block of the Try, Catch.

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
From another post and not my answer:

Stack/Heap allocation takes time. So when you create an instance of a form, space is allocated for it... when you're done with the form, close it, dispose it and set it to nothing. The memory is still allocated for your application. If then invoke a new instance of the form, it *should* re-allocate the same space for it, re using the same memory space. But that only happens if it's the same form and the previous one was properly cleared/removed/disposed/whatever. And the new object can fit in the same footprint.

I try to stay in the habit os disposing of anything that can be (with exceptions like buttons).
 
Thanks for the advice guys.

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top