title: C++ Memory leak caused by a pointer being set to NULL in the class destructor
body: <p>I have a class with the .h file as:</p>
  
  <pre><code>class dbsk2d_ishock_node : public dbsk2d_ishock_elm{
  protected:
      dbsk2d_ishock_edge* _cShock;
      //Some other variables
  public:
      dbsk2d_ishock_node (int newid, double stime, vgl_point_2d&lt;double&gt; Or); //Constructor
      virtual ~dbsk2d_ishock_node (); //Destructor
      //Some other functions
  }
  </code></pre>
  
  <p>The .cxx file looks like:</p>
  
  <pre><code>//Constructor
  dbsk2d_ishock_node::dbsk2d_ishock_node (int newid, double stime, vgl_point_2d&lt;double&gt; Or) : dbsk2d_ishock_elm (newid, stime)
  {
      _cShock = NULL;
      //Some other variables
  }
  
  //Destructor
  dbsk2d_ishock_node::~dbsk2d_ishock_node ()
  {
      _cShock = NULL;
      //Some other variables
  }
  </code></pre>
  
  <p>Now the constructor for this class sets <code>_cShock = NULL;</code> and the virtual destructor also sets <code>_cShock = NULL;</code>. </p>
  
  <p>So when the destructor is called, it will just set the pointer to NULL but the actual memory being poined to won't be destroyed, right, causing a memory leak? </p>
  
  <p>This class is called many times and after a certain point the program crashes due to <em>excessive</em> memory usage. How do I fix this?</p>