I'm trying to develop some tree-like data structure with Java.
class MyTree {
private Node root;
}
class Node {
private HashMap<Character, Node> children;
private String content;
// some other data members
}
As you see, each Node
contains another Node
, which is its children so that I can build a list like this: MyTree.root -> child1 -> child2 -> child3
.
Now, if I want to delete/free this tree, can I simply do root = null;
or must I loop to set each element to null? I don't know how gc exactly works in this case...