Class1:
public class FunctionBlocks
{
List<Hashtable> _htLogicalNodeList;
public FunctionBlocks()
{
_htLogicalNodeList = new List<Hashtable>();
FunctionBlock fb = new FunctionBlock();
fb.AddDODASignalList(new Hashtable);
_htLogicalNodeList.Add(fb.LogicalNodeHash);
fb = null;
}
}
Class2:
public class FunctionBlock
{
Hashtable _htLogicalNode;
public FunctionBlock()
{
_htLogicalNode = new Hashtable();
}
public Hashtable LogicalNodeHash
{
get{return _htLogicalNode;}
set{_htLogicalNode = value;}
}
public void AddDODASignalList(Hashtable doDASignal)
{
_htLogicalNode.Add(doDASignal);
}
}
In this example I wan’t to dispose “_htLogicalNode” . “fb” object I have make it as null ,Eventhough “FunctionBlocks” instance have “_htLogicalNode” references. How I can dispose “_htLogicalNode” instance.
What do you mean by “dispose”? You could have
FunctionBlockimplementIDisposablein which case you could use the following:However I can’t see anything in
FunctionBlockthat needs disposing, and so doing this would be pointless – theIDisposableinterface / pattern is essentially just a fancy / robust way of calling a method when you are done with an object. Unless you do something in the implementedDisposemethod then this does nothing.If by “dispose” you mean free up the memory then the answer is that you don’t need to do anything (you don’t even need to set
fbto null). Simply letfbgo out of scope and the garbage collector will collect it and free up the used memory in its own time.You may find that the memory used by
fbis not freed immediately – this is perfectly normal and to be expected. There are ways of forcing the garbage collector into doing “its thing” when you want it to, but doing this is very bad practice.