Reputation: 14864
I want to clear a BST so as to take advantage of the garbage collector. So, to clear a BST, is it sufficient to set the root to null, so that I end up with a bunch of abandoned nodes with no pointers to them? Or is it better to set each node to null?
I am also concerned about weak reference and strong reference, etc.
Upvotes: 3
Views: 487
Reputation: 19837
Any object that cannot be reached by any live thread will be eligible for garbage collection.
Based on that:
Conclusion:
Just set the root to null and let GC to traverse the tree in the good moment for him :)
Upvotes: 1