As the title suggests, I was wondering if using DataTable (or any object-type) as a parameter or return value causes memory leaks? Suppose I have 3 different functions:
public DataTable InitDT()
{
//Create and Initializes the dataTable columns, and returns a DataTable
DataTable dt = new DataTable();
DataColumn column = new DataColumn();
column.ColumnName = "Id";
dt.Columns.Add(column);
return dt;
}
public DataTable PopulateDT()
{
//Populate an Initialized DataTable and return it
DataTable dt = InitDT();
DataRow row;
row = dt.NewRow();
dt.Rows.Add(row);
return dt;
}
public void ReadDT()
{
//Read return DataTable
DataTable dt = PopulateDT();
foreach (DataRow r in dt.Rows)
{
txtId.text = r[0].ToString();
}
dt.Dispose();
}
On my code, only the last function calls dt.Dispose();
so I was wondering what happens to the 2 previously created DataTables. Does the garbage collector already cleans them?