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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does vb.net have memory leaks?

Status
Not open for further replies.

jw970170

Programmer
Aug 8, 2005
38
I have some code that looks like there is a memory leak (ie...in C++, there would be a memory leak since I didn't release the memory when I created the second instance of mycommand). The code is below

Dim myCommand As New SqlCommand(myDropTable, Conn)
Try
myCommand.ExecuteNonQuery()
Catch myException As Exception
'MsgBox(myException.ToString())
'Nothing to delete for now
End Try

'Possible memory leak?? VB vs C++
myCommand = New SqlCommand(myCreateTable, Conn)

In VB, do I have to release the memory somehow . Should I do something like

delete myCommand
'Possible memory leak?? VB vs C++
myCommand = New SqlCommand(myCreateTable, Conn)


Thanks in advance :)
 
mycommand.Dispose()

If something has a dispose method then you can use it to release the resources faster.
 
I've been reading up on garbage collecton (I'm trying to use IMAPI and imapi.exe stays open after my program closes.)
From what I read it seems that calling dispose on items that implement idisposable won't do any harm, might prevent problems, and should get items cleaned up earlier (the automatic GC may take longer). There's more here:
My Imapi problem must lie with some unmanaged resource not getting disposed, but there is a lot going on. I'll have to simplify it and try to find one thing that leads to the problem.
 
Wow. Ok, thanks everyone for your help. Looks like I don't really have to worry about it...but I can if I so choose :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top