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?
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).