I have a large network of nodes in memory, everyone has a link to the same object.
As an example. Suppose every node on the network has this class.
public class Node { public Context context { get; private set; } public Node Parent { get; private set; } public List<Node> Children { get; private set; } public Node(Context pContext, Node pParent, List<Node> pChildren) { this.context = pContext; this.Parent = pParent; this.Children = pChildren; } }
The context property is an object that is passed to the constructor for all nodes in the network.
Assuming that the network is very large (thousands of nodes), and they form a tree structure. Will this common shared link between them lead to memory leaks?
If I detach a branch in the tree by setting Parent to Null . Will this thread correctly garbage collection in C# , even if context remains a reference to this shared object?
What coding practices should be used to ensure proper operation.
cgTag source share