BleepingComputer.com: Disposing objects and releasing resources in VB .Net

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Disposing objects and releasing resources in VB .Net

#1 User is offline   aommaster 

  • I !<3 malware
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Team
  • Posts: 5,190
  • Joined: 08-June 08
  • Gender:Male
  • Location:Dubai

Posted 05 August 2009 - 08:27 AM

Hi!

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!

This post has been edited by aommaster: 05 August 2009 - 08:28 AM

My website: http://www.aommaster.com
Posted Image
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM

All my help is free. However, if you would like to make a donation, then please click here.



Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users