lundi 22 mai 2017

Delete object pointer in hashtable

I have a hashtable with chaining where each node is:

struct Node
{
    Object * objPtr;
    Node * next;
}

When I read data from the file I create an object:

...
Object * currObj;
currObj = new Object; //Causes memory leaks (doesn't get deleted)

//Save data
currObj->setData(data);
//Insertion
insert(*currObj);

What would be the correct destructor for such a case? I have a destructor for table and destructor for Object, but currObj = new Object seems to cause leaks.

Aucun commentaire:

Enregistrer un commentaire