I'm currently working on a program that I decided to split up into classes (it made managing the program a lot easier).
Currently, each class has a constructor that opens a connection to a database, creates a data adapter and a data set. Then, it writes the data from the database table to the dataset, and finally, generates a dataview (due to the fact that I can sort and hence, find indexed data quickly. On that note, this is good programming practice, yes?). This Dataview is stored in the object as a property, to which other functions can then access.
The main body of the code will call this object (hence, opening the link to the DB, and in essence, generate the dataview), call a number of functions (these search for entries in the database, and the function will return a requested value), perform a few other functions, and then, will move on to another object.
My problem is this: I haven't gotten rid of the object. This means that somewhere in memory, is an area allocated to that dataview, yes? How do I tell VB .Net that this object is no longer needed and whatever memory resources were used by that can be cleared?
I believe I have to use the dispose function, so I wrote something like this into my class:
Sub Dispose() Implements System.IDisposable.Dispose Static done_before As Boolean = False If done_before Then Exit Sub done_before = True End Sub(I also had an Implements IDisposable at the top of the class).
However, I don't believe that I am doing this right, because after I called the dispose function, I was still able to call a function inside the object.
What would be the correct way of doing this in terms of good programming practice?
Thanks everyone!
Edited by aommaster, 05 August 2009 - 08:28 AM.