Looking at the following code:
class Class1
{
private List<object> _listOfAnything;
~Class1() //is it worth it?
{
//set null to all items of the list
if (_listOfAnything != null)
{
if (_listOfAnything.Count > 0)
{
for (int i = 0; i < _listOfAnything.Count; i++)
{
_listOfAnything[i] = null;
}
//clear list
_listOfAnything.Clear();
}
//set list to null
_listOfAnything = null;
}
}
public void DoSomething()
{
//create list and add items to it
_listOfAnything = new List<object>();
_listOfAnything.Add(new object());
_listOfAnything.Add(new object());
_listOfAnything.Add(new object());
//do something
}
}
class Class2
{
private void DoSomething()
{
//instanciate Class1
Class1 class1 = new Class1();
//do something with Class1
class1.DoSomething();
//set null to Class1
class1 = null; //do I need to set it no null?
}
}
Do I really need to set Class1
to null and clear Class1._listOfAnything
?