   Delete pointers from stl map?
  Hi, I am currently working on a pathfinding algorithm for AI, this is not important though. Right now I am creating nodes on the fly and inserting them into astl map container. I am not sure how to delete the items in the new nodes I inserted into the container cause just calling clear on the map doesn't delete the items that were dynamically allocated any help on how to delete dynamically allocated items insereted into a stl map please help? Here is some example code where you can see me creating(calling new) the objects and inserting them into the map. Also the function Im trying to write to delete the memory and clear the map.// if adjacent tile is valid and the tile is adjacent and its weight is not 0if (adjacentTile != NULL && (*isAdjacent)(current->tile,adjacentTile) && adjacentTile->getWeight() != 0){// Check to see if tile already exist in our created listif(!created[tileMap.getTile(rowIndex, colIndex)]){// If not in our list create a new one and add it to the created and open list PlannerNode* newNode = new PlannerNode(tileMap.getTile(rowIndex,colIndex),current);open.push_back(newNode);created[tileMap.getTile(rowIndex,colIndex)] = newNode;}}sorry if code looked messy when inserted it messed it all up when I pasted itvoid BreadthFirstSearch::reset(){    // TODO: Clean up after the algorithm.    std::map<Tile const*,PlannerNode*>::const_iterator itr;    for (itr = created.begin(); itr != created.end(); ++itr)    {   // Not sure what to do here to delete.delete }}
  All you need is a delete *itr. [sad]You should also be using the find() function on the map to detect if an element is already in the map, since operator[] will create one for your if it doesn't exist.  This might be the behavior you want, but I just wanted to point it out.   ;  I don't think that works, Zipster; its a map:// delete itr->first;  // Whoops, this is tileMap's Tile!delete itr->second;Alternatively, you can use std::tr1::shared_ptr or boost::shared_ptr instead of raw pointers to handle the deletion automatically.   ;Quote:Original post by _fastcallI don't think that works, Zipster; its a mapYes, for some reason my mind was thinking vector... :-/   