|
|
|
|
![]() ![]() |
Jan 12 2005, 08:38 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
Hi everyone,
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! |
|
|
|
Jan 12 2005, 10:11 PM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 399 Joined: 14-November 04 From: Elysium Member No.: 2,280 |
why don't you just do a new()...delete()
or if you're in C, freelloc, etc. around the whole thing? |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 11th October 2008 - 03:19 AM |