I implement a binary tree, and I need to override the clear () method, which will remove all items from the collection. The question is - am I doing (piccha attached)? (hope for a garbage collector) And if wrong / not optimal, then how best?

enter image description here

  • 2
    Yes, right. If the item is not referenced, the collector fixes it itself. - michael_best
  • Even if you run around the tree and set null as children in each node, the tree will not take up less space in memory anyway. Therefore, it is better to shoot the head off right away and let gc further remove. - Olexiy Morenets

0