question

MuppalaKeerthi-4630 avatar image
0 Votes"
MuppalaKeerthi-4630 asked TimonYang-MSFT answered

VS Diagnostic Tools Shows that the memory consumed while creating a DataTable is not released even after GC.Collect()

VS Diagnostic Tools Shows that the memory consumed while creating a DataTable is not released even after GC.Collect().

Code Snippet:

using (DataTable table = new DataTable())
{
for (int column = 0; column < 1024; column++)
{
table.Columns.Add("Name" + column);
}
for (int row = 0; row <= 75000; row++)
{
table.Rows.Add();
for (int column = 0; column < 1024; column++)
{
table.Rows[row][column] = "Kim" + row + column;
}
}
}
GC.Collect();

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DuaneArnold-0443 avatar image
0 Votes"
DuaneArnold-0443 answered
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

GC.Collect() cannot guarantee that all memory will be collected.

Use this method to try to reclaim all memory that is inaccessible. It performs a blocking garbage collection of all generations.

All objects, regardless of how long they have been in memory, are considered for collection; however, objects that are referenced in managed code are not collected.

You can also take a look at the discussion on this issue in this post:

.NET Garbage Collection behavior (with DataTable obj)

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.