D
dudi
I am encountering the following strange problem which causes the application
to use more memory then it should.
I have 5 database tables. lets pretend I want to load each one of them into
a dataTable. then, run over all the rows of the dataTable and for each cell
in the dataRow concatenate a string (the value in the cell is a string to
begin with).
I expect the memory to go up every time I load a dataTable, even go up when
I modify the rows, but I expect it to
go down when the loop ends and then go up again when the new dataTable is
loaded. however, the memory simply adds-up... each dataTable just adds to
the memory and it is as if the last dataTable is not releases. more
precisely, I found the problem is not the dataTable but the strings. it
seems the string (new, old) that I modify are not cleared from the memory.
here is a sample of what I do and causes the memory 'leak'. below this
sample I also specify what I did that DOES work (seems to have no memory
build up), however, that solution is not acceptable:
'------------------------
Dim tables() As String = {"5Tbl", "4Tbl", "3Tbl", "2Tbl", "1Tbl"}
For Each table As String In tables
Console.WriteLine("loading table:" + table)
'loads the table into memory
Dim dt As DataTable
Dim sqlIns As String = "SELECT * FROM " + table
dt = m_dbMaster.getDataTable(sqlIns)
'added this just to make sure
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
System.Threading.Thread.Sleep(5000)
Console.WriteLine("working table:" + table)
Dim dr As DataRow
For Each dr In dt.Rows
dr("w1") = CStr(dr.Item("w1"))
dr("w2") = CStr(dr.Item("w2"))
dr("w3") = CStr(dr.Item("w3"))
dr("w4") = CStr(dr.Item("w4"))
Next
System.Threading.Thread.Sleep(5000)
'------------------------
OK, so before you tell me it is probably the getDataTable function that is
not working well hear this:
if I change the lines
dr("w1") = CStr(dr.Item("w1")) to
dr("w1") = "xxxxxxxxxxxxxxxxxxxx" (that is, I am replacing the value in the
cell with a literal instead of a string generated from its original value)
the EVERYTHING IS JUST FINE!!! memory goes up and down as it is supposed to.
anyone has any idea what is going on?
regards and thanks in advance.
to use more memory then it should.
I have 5 database tables. lets pretend I want to load each one of them into
a dataTable. then, run over all the rows of the dataTable and for each cell
in the dataRow concatenate a string (the value in the cell is a string to
begin with).
I expect the memory to go up every time I load a dataTable, even go up when
I modify the rows, but I expect it to
go down when the loop ends and then go up again when the new dataTable is
loaded. however, the memory simply adds-up... each dataTable just adds to
the memory and it is as if the last dataTable is not releases. more
precisely, I found the problem is not the dataTable but the strings. it
seems the string (new, old) that I modify are not cleared from the memory.
here is a sample of what I do and causes the memory 'leak'. below this
sample I also specify what I did that DOES work (seems to have no memory
build up), however, that solution is not acceptable:
'------------------------
Dim tables() As String = {"5Tbl", "4Tbl", "3Tbl", "2Tbl", "1Tbl"}
For Each table As String In tables
Console.WriteLine("loading table:" + table)
'loads the table into memory
Dim dt As DataTable
Dim sqlIns As String = "SELECT * FROM " + table
dt = m_dbMaster.getDataTable(sqlIns)
'added this just to make sure
System.GC.Collect()
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
System.Threading.Thread.Sleep(5000)
Console.WriteLine("working table:" + table)
Dim dr As DataRow
For Each dr In dt.Rows
dr("w1") = CStr(dr.Item("w1"))
dr("w2") = CStr(dr.Item("w2"))
dr("w3") = CStr(dr.Item("w3"))
dr("w4") = CStr(dr.Item("w4"))
Next
System.Threading.Thread.Sleep(5000)
'------------------------
OK, so before you tell me it is probably the getDataTable function that is
not working well hear this:
if I change the lines
dr("w1") = CStr(dr.Item("w1")) to
dr("w1") = "xxxxxxxxxxxxxxxxxxxx" (that is, I am replacing the value in the
cell with a literal instead of a string generated from its original value)
the EVERYTHING IS JUST FINE!!! memory goes up and down as it is supposed to.
anyone has any idea what is going on?
regards and thanks in advance.