Possible Duplicate:
Should I Dispose() DataSet and DataTable?
I am using a 3 tier architecture in my application,on Datalayer i am simple getting dataset
Dataset dset= new Dataset();
try
{
dset = SqlHelper.ExecuteDataset(Con, CommandType.StoredProcedure, "StoredProcedureName", arParms);
}
catch
{}
finally
{
Con.Close();
dset.Dispose()
}
Is there any performance benefit of disposing the data set object?
If an object implements
IDisposable, you should dispose of it.The best way to dispose of any object implementing
IDisposableis to wrap the creation in ausingstatement:The above generates the correct disposal pattern for the created object. Using this pattern is a good rule of thumb – if you do it all the time, chances that you forget to dispose of something important are drastically lowered.
As Tim Schmelter commented, I did not address the issue of performance.
In the case of datasets, there will be no performance benefit, as disposal is suppressed in the constructor, as described in the answers to this SO question. At the same time, the overhead of calling dispose is minimal.
I suggest you test both approaches for your specific use case to see which one performs better and whether the benefits of using one option over the other are worth the downsides.