title: How to write destructor for Trie tree
body: <p>I've been working on an assignment which has us use a trie tree to add words from a dictionary into the tree and then search through it. The part I'm stuck on is the class destructor. This is the first time I've had to deal with a destructor/memory management and what I have below is my best guess after searching through the resources I have at the moment.</p>
  
  <p>Am I on the right track? Each node has 27 children (the alphabet and a delimiter), so I'm hoping it deletes them all from the leaves to the root.</p>
  
  <pre><code>class Trie
  {
  private:
      TrieNode *_root = nullptr;
      TrieNode *_current = nullptr;
      TrieNode *_child = nullptr;
  
      string current_word;
      bool setRoot = false;
  
  protected:
  
  public:
      Trie()
      {
          _root = new TrieNode{};
      }
  
      virtual ~Trie()
      {
          //TODO: clean up memory
          DestroyRecursive(_root);
      }
  
      void Trie::DestroyRecursive(TrieNode* node)
      {
          if (node != nullptr)
          {
              for (TrieNode* child : node-&gt;getChildren())
              {
                  delete(child);
              }
          }
      }
  </code></pre>
  
  <p>How can I check if a destructor is working properly? I'm using Visual Studio.</p>