How can i release the memory used by a datatable object say dt; so that i can use it for a different set of values? is it enough dt=null; is ther any advantage in doin this?
Asked
Active
Viewed 566 times
2 Answers
0
You could use table.Clear();
or less expensive simply table = new DataTable();
. Since DataTable
implements IDisposable
you could also call table.Dispose();
or use it with a using
-statement. However, that's not really necessary since a DataTable
does not use unmanaged resources. It's just an in-memory object.
Side-note: you don't need to set it to null
manually, the Garbage Collectior takes care of it, so there's really no need to do it.

Community
- 1
- 1

Tim Schmelter
- 450,073
- 74
- 686
- 939
0
Public Shared Sub CleanupDataTable(ByRef dtToCleanup As DataTable)
If dtToCleanup IsNot Nothing Then
dtToCleanup.Rows.Clear()
dtToCleanup.Constraints.Clear()
dtToCleanup.ParentRelations.Clear()
dtToCleanup.ChildRelations.Clear()
dtToCleanup.PrimaryKey = Nothing
dtToCleanup.Columns.Clear()
dtToCleanup = Nothing
End If
End Sub

pprajapati
- 25
- 6