问题描述:

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?

网友答案:

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.

Setting Objects to Null/Nothing after use in .NET

相关阅读:
Top