   (C++) Memory leak in pathfinding code.
  Code located here: http://paste.bradleygill.com/index.php?paste_id=65293I modified this from a homework assignment I had awhile ago, which was... based on some pseudocode from a Peter Norvig textbook and I'm inclined to think it was written with a garbage collected language in mind.Anyway, in terms of outward behavior, it seems to work correctly, but I have a sizable memory leak thanks to passing in new Node(toCopy) objects to the Node constructor for the parent argument. Normally I'd just put in a destructor that delete the Node* parent objects in each Node; however doing that sort of causes the deletion to cascade upwards, wiping out the path I'm trying to generate.Additionally deleting the parent pointers later while I generate a path from the goal node, while apparently possible, is sort of fruitless since I don't catch all the nodes that are otherwise never used in the goal path.So, any ideas? I was thinking of flagging Nodes that point to parents used by the path so that they wouldn't their parents but I'm not sure how to do that or if it's even the right course of action.   
  Why are you generating new nodes? you can't run more than 1 A* at a time, typically, so just have one fixed set of nodes each with a parent pointer. While pathfinding, just set the pointers. At the end you reconstruct a path by back iterating the parent links and stuffing pointers into a std::vector or some other dynamic container and pass that to the AI that's going to do the path following. When that entity is done, they just deallocate the container of pointers (not the nodes themselves). You definitely don't need to copy the entire node, that's wasteful.-me   ;  Okay so I have to admit I didn't entirely understand your solution. I still generate new nodes for the priority queue since I'm not really sure how to get around that. Anyway, it did give me an idea, though. Instead of generate new nodes and passing those to the parent pointer, I just copy expanded nodes from the priority queue to a stable structure (in this case a list), pop them, and pass the stored Nodes from the list as arguments to the parent pointer.http://paste.bradleygill.com/index.php?paste_id=65318Anyway it's not leaking as badly but it's still leaking and now I'm really not sure why since I believe I got rid of every explicit new statement.[Edited by - MeshGearFox on November 19, 2010 5:10:13 PM]