x

Started by
4 comments, last by Carbon101 9 years, 4 months ago

...

 

Advertisement

If the nodes are never freed, that would indeed leak memory. If you reached that conclusion by searching for 'delete newNode' in the file, that would not mean anything. Nodes would have to be deleted when a node is removed or inside LinkedLists destructor. In neither of these situations you would normally call the local variable newNode though.

I'm guessing that that somewhere there is a LinkedList::pop() method that would have to delete the node and exchange next and prev pointers, and LinkedList::clear() would delete all of the nodes.

So when a value is removed from the list, thats when its node should be deleted. (and the only time)

...

If you have any doubt its leaking memory you better use one from the standard library instead. That looks like a bad list implementation anyway, as its traversing the whole list each time its adding a node, when it could cache a pointer to the last node or, depending on use, could just add the new node to the head.

...

This topic is closed to new replies.

Advertisement