Although my question is similar to Freeing memory in caller or callee?, this is for C# and its more towards who should create an object rather then who should free it.
Which approach (or some other approach) represents best practice? My intuition says Approach 1 because who knows who instantiated the object otherwise? On the other hand, a DataTable doesn't need explicit disposing, so who cares who instantiates it?
Approach #1
DataTable dataTable = dataAccessLayer._QueryDbGetAllTablesForDb(new DataTable());
.
//or
.
DataTable dataTable = new DataTable();
dataTable = dataAccessLayer._QueryDbGetAllTablesForDb(dataTable);
.
//then
DataTable _QueryDbGetAllTablesForDb(DataTable datatable);
{
.
sqlDataAdapter.Fill(dataTable);
.
return dataTable
}
Approach #2
DataTable dataTable = dataAccessLayer._QueryDbGetAllTablesForDb();
.
//then
DataTable _QueryDbGetAllTablesForDb();
{
.
DataTable dataTable = new DataTable();
sqlDataAdapter.Fill(dataTable);
.
return dataTable
}