C++ for loop causing memory leak? -
i've got game server made in c++ , noticed memory count continuously growing.
i start server up, , open task manager (windows 7) , @ memory it. memory fine 20 seconds after goes , doesn't stop.
i've narrowed down code that's doing this:
for(std::vector<door>::iterator door = mymap()->doors.begin(); door != mymap()->doors.end(); ++door){ }
i don't need code inside of loop, it's code has memory leak. memory leak? it's standard loop going through vector object.
the code above run in function call gets updated through while loop on separate thread. if comment code out memory count fine.
edit: mymap() definition:
map* player::mymap(){ if(maplist == null){ //cout << "maplist null" << endl; return null; } //std::map<std::string, map*> &mymaplist = *maplist; //cout << "getting map: " << (*maplist)["f1"]->blocks.at(0).x << endl; return (*maplist)[strdup(room.c_str())]; }
please let me know if need provide additional code.
now provided definition of mymap
, can tell memory leaks come call strdup
. pointer returned function should freed (by call free
), since calls malloc
.
Comments
Post a Comment