I have a class with the .h file as:
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<double> Or); //Constructor
virtual ~dbsk2d_ishock_node (); //Destructor
//Some other functions
}
The .cxx file looks like:
//Constructor
dbsk2d_ishock_node::dbsk2d_ishock_node (int newid, double stime, vgl_point_2d<double> Or) : dbsk2d_ishock_elm (newid, stime)
{
_cShock = NULL;
//Some other variables
}
//Destructor
dbsk2d_ishock_node::~dbsk2d_ishock_node ()
{
_cShock = NULL;
//Some other variables
}
Now the constructor for this class sets _cShock = NULL;
and the virtual destructor also sets _cShock = NULL;
.
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?
This class is called many times and after a certain point the program crashes due to excessive memory usage. How do I fix this?