I see a lot of code where the objects are set to null in the finally
section or at the end of a method, for example:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void buildUpdates(int batchId, string mkt)
{
aplUpdate oDU;
DataSet ds;
DataTable dtTbls;
DataTable dtData;
List<dbVer> resp;
try
{
oDU = new WEB_APL.APL.aplUpdate(MyWeb.Properties.Settings.Default.DBCon);
ds = new DataSet();
ds.DataSetName = batchId.ToString();
dtTbls = oDU.getDetails(true);
resp=GetDBVersions();
foreach (DataRow dr in dtTbls.Rows)
{
.....
}
ds.WriteXml(HttpContext.Current.Server.MapPath("~") + "\\" + ds.DataSetName + ".xml", XmlWriteMode.WriteSchema);
}
catch (Exception ex)
{
throw ex;
}
finally
{
oDU = null;
ds=null;
rest=null;
dtTbls=null;
dtData=null;
}
}
I think this is unnessesary since expired objects will be handled automatically by the .NET garbage collector
.
Is there a reason why one should reset to null
?