I'm working with stl maps, I seem to be experiencing a memory leak somewhere, the debugger isn't giving me any warning about it though. I thought maps and other containers are supposed to free themselves once they fall out of scope?
Code:
void function1()
{
map<CString, set<CString> > local_map;
// insert some stuff into local_map...
local_map["key"].insert("somethin");
local_map["key"].insert("somethin else");
// for every key of local map, I would like to create a
// 'minimap' that is just that one key and its associated
// <set> values.
for (map<CString, set<CString> >::iterator i = local_map.begin(); i != local_map.end(); i++) {
// The memory for *pm will be deleted on the receiving end.
map<CString, set<CString> > *pm = new map<CString, set<CString> >;
pm->insert(pair<CString, set<CString> >(i->first, i->second));
PostMessage(WM_SENDMAP, (WPARAM)pm, NULL);
}
// local_map should deallocate itself right here yes?
}
void OnMessageFunctionReceiveMap(WPARAM w, LPARAM l)
{
// This is the minimap posted from function1.
map<CString, set<CString> > *pReceivedMap = (map<CString, set<CString> > *)w;
// Now I would like to set a member variable of
// a thread object equal to the received mini map.
m_pThreadObject->SetMap(pReceivedMap);
// Now the memory allocated for this minimap in function1
// should be taken care of?
delete pReceivedMap;
}
void CThreadObject::SetMap(map<CString, set<CString> > *map)
{
// I would like m_MemberLocalMap to be filled with the
// values from *map, which it does, but does this
// mean that m_MemberLocalMap will incorrectly still
// be retaining any allocated memory from *map?
m_MemberLocalMap = *map;
}
Again, I don't receive any memory leak warnings, but everytime I run the app I keep getting an extra 20k in memory usage. I have tested all this out before adding the <map>, with no problems so I'm pretty sure it has something to do with this.
Thanks for any info!

