我们有如下代码来修复 CA2000:在失去范围之前处理对象 ( http://msdn.microsoft.com/en-us/library/ms182289.aspx )。当 tbl 被赋值为 null 时,它引用的对象是否会被垃圾回收?
private DataTable BuildRequestDataTable(Factory tableFactory)
{
DataTable tbl = null;
DataTable requestTable = null;
try
{
tbl = tableFactory.CreateTable();
requestTable = tbl;
tbl = null;
}
finally
{
if (tbl != null)
{
tbl.Dispose();
}
}
return requestTable;
}