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

Releasing some memory from running program

Status
Not open for further replies.

Antithott

IS-IT--Management
Jan 20, 2006
90
DK
Hi.

Ive made a program which Reads data from a MySql database, in the beginning it uses about 5mb of memory, but because there is a Auto Update in the program, it raises by about 0.215 used memory each update.

So i was kinda hoping there was a way i could clear the used memory or somehow make it lower, I know that 5mb prolly isnt much, but potentially some could let it run for days, and it would be a huge memory stealer.

- Anti
 
How are you writing the data to the database?

Are you:
using a custom Dataset?
building your statement&connection in code?
using a com object?
using threads?

A little more detail would help.

-The answer to your problem may not be the answer to your question.
 
Im reading the data by using threads.

This is the start of my sub to get data from Database.
Code:
Dim MyConString As String = DatabaseInformation

            Dim MyConnection As New OdbcConnection(MyConString)
            MyConnection.Open()

            Dim MyCommand As New OdbcCommand
            MyCommand.Connection = MyConnection

            Dim StrSql As String = "SELECT * From Sag WHERE Status = 'Lukket'"
            Dim Cmd As OdbcCommand = New OdbcCommand(StrSql, MyConnection)

            Dim Reader As OdbcDataReader = Cmd.ExecuteReader

            While (Reader.Read())

                 If UserSecurityLevel = 5 Then
                    If Reader.IsDBNull(9) = False And Reader.IsDBNull(2) = False Then
                        If Reader.GetString(9) <> 1 Or Reader.GetString(2) = UserUserName Then

                           
                            If Reader.IsDBNull(0) = False Then
                                                          temp1 = Reader.GetInt64(0)
                            End If


Im loading the data into variables and then passing those on in the thread to add the values to a listview.

Im setting those values to String.empty in the end of the sub
 
rather than String.Empty set it to NOTHING.

As well, are you closing your connection after you open it?

-The answer to your problem may not be the answer to your question.
 
Are you calling Close and Dispose on your connection and command, and setting them to Nothing after they are no longer needed?

MyConnection.Close()
MyConnection.Dispose()
MyConnection = Nothing

MyCommand.Dispose()
MyCommand = Nothing



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
The Myconnection i was setting to Close and nothing, i did not dispose it. Ill change that if it can have effect on the memory.

MyCommand i was also setting to nothing but wasnt used Dispose. Will try that on both.
 
When you are finished with an object, you should always call Dispose on objects that implement it because this basically informs the garbage collector that it is OK to release the memory allocated to this object.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top