I'm getting a major headache using datatables inside VB.NET (Framework 2.0 and 3.5)
I'm basically reading some data from SQL into a datatable and then passing that datatable onto another thread which deals with writing out some data to a COM object before clearing the rows and repeating the loop again.
At the moment the application is reaching over 230Mb+ and then at some point crashing because it ran out of memory.
I'm sure that the GC isnt clearing up the datatable or datarows .
The code basically performs the following (is there another way to force the removal of the datarows/datatable from memory)?
Repeat process again (this may occur 10000+ times), on average there could be 5000 records in the datatable during each loop.
using Framework V2.0 and even tried V3.5.
Any help please.....
Thanks
Ron
I'm basically reading some data from SQL into a datatable and then passing that datatable onto another thread which deals with writing out some data to a COM object before clearing the rows and repeating the loop again.
At the moment the application is reaching over 230Mb+ and then at some point crashing because it ran out of memory.
I'm sure that the GC isnt clearing up the datatable or datarows .
The code basically performs the following (is there another way to force the removal of the datarows/datatable from memory)?
VB.NET:
--Create array of new records
Dim Ddrows(aMsrTags.Length - 1) As DataRow
For ii = 0 To aMsrTags.Length - 1
Ddrows(ii) = dtDataTable.NewRow()
Next
'Read SQL and copy data into datarows
---Add rows to datatable
dtDataTable.Rows.Add(Ddrows(i - 1))
dtDataTable.AcceptChanges()
--Pass datatable to thread
mythread.DumpDataTable(dtDataTable)
(merges the dtDatatable with the thread datatable, maybe its keeping a reference here and not forcing a clean up?)
--remove all rows added
dtDataTable.Rows.Clear()
dtDataTable.AcceptChanges()
--force GC
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
Repeat process again (this may occur 10000+ times), on average there could be 5000 records in the datatable during each loop.
using Framework V2.0 and even tried V3.5.
Any help please.....
Thanks
Ron