Reputation: 21641
I've the following code
DataView dvTest= dsTest.Tables[1].Copy().DefaultView;
Will the copy of the (huge) dataset dsTest be persisted in the memory or will it be Garbage Collected by default?
Does it copy the whole dataset to the memory? When the GC happens?
Upvotes: 2
Views: 239
Reputation: 32568
This may actually be two questions: 1) anonymous object lifetime, and 2) dataset lifetime.
for 1) - as soon as there are no references to the object, it is eligible to be garbage collected, just like a "named" object.
for 2) The defaultview of a datatable has a reference to the table, so the datatable will remain in memory until you no longer hold a reference to the view (or any rows, etc - anything that references the dataset).
Upvotes: 3
Reputation: 48949
It is very likely that it will hang around since the object referenced by DefaultView
itself holds a reference to the object returned from Copy
. And, of course, it will eventually be collected once it becomes unreachable. But, at the very least, your dvTest
will cause it to persist for awhile anyway.
Upvotes: 2
Reputation: 38454
You are copying the DataTable and then holding a reference to it in dvTest via DefaultView, so no it will not be garbage collected until dvTest goes out of scope.
Upvotes: 0