STL Map
-
Hi Here is sample code.... LocoDetails *locoValue = new LocoDetails(str1, ltime, latitude, longitude, speed, direction, trackPos, trackNum, alarmsNum, failsNum); Later i just add this to a STL map locoDetailsList.insert(pairstd::wstring,LocoDetails\*(locoValue->GetLocoID(),locoValue)); for(pastIterater = locoDetailsList.begin();pastIterater != locoDetailsList.end();pastIterater++) { locoDetailsList.erase(pastIterater++); } Will the memory occupied by locoValue get removed or there a memory leak. How can i solve this........ Thanks
-
Hi Here is sample code.... LocoDetails *locoValue = new LocoDetails(str1, ltime, latitude, longitude, speed, direction, trackPos, trackNum, alarmsNum, failsNum); Later i just add this to a STL map locoDetailsList.insert(pairstd::wstring,LocoDetails\*(locoValue->GetLocoID(),locoValue)); for(pastIterater = locoDetailsList.begin();pastIterater != locoDetailsList.end();pastIterater++) { locoDetailsList.erase(pastIterater++); } Will the memory occupied by locoValue get removed or there a memory leak. How can i solve this........ Thanks
The map only holds a pointer to the object. You're responsible for deleting the object itself.
--Mike-- Dunder-Mifflin, this is Pam
-
Hi Here is sample code.... LocoDetails *locoValue = new LocoDetails(str1, ltime, latitude, longitude, speed, direction, trackPos, trackNum, alarmsNum, failsNum); Later i just add this to a STL map locoDetailsList.insert(pairstd::wstring,LocoDetails\*(locoValue->GetLocoID(),locoValue)); for(pastIterater = locoDetailsList.begin();pastIterater != locoDetailsList.end();pastIterater++) { locoDetailsList.erase(pastIterater++); } Will the memory occupied by locoValue get removed or there a memory leak. How can i solve this........ Thanks
You are responsible for deleting the pointer objects yourself. Another approach is to use a reference-counted smart pointer like boost::shared_ptr.
Pax Domini sit semper vobiscum