Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Free Memory After Out Of Scope?
kvarnerexpress
post 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!
Go to the top of the page
 
+Quote Post
osknockout
post 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?
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Will Work Card On 4 Gb In Nokia N73 ?(2)
  2. Memory Card Issue(5)
  3. Sony Psp Memory Card(15)
  4. Virtual Memory Error... Windows Xp(5)
  5. Game Dev Team(4)
  6. Memory Trick To Speedup Windows Xp(28)
  7. Allowed Memory Size Exhausted(4)
  8. Allowed Memory Size Exhausted(1)
  9. Password Protecting A Flash Drive(6)
  10. Windows Xp Memory(5)
  11. Psp Memory Cards(1)
  12. Firefox 3 - Lowest Memory Usage(11)
  13. Memory(ram) Question(6)
  14. Memory Usage(3)
  15. Data Recovery Software(3)
  1. Fixing Firefox's Large Use For Memory...(12)
  2. Exercise Helps Rebuild Memory(13)
  3. Bad Ram Can Cause Computer Failure To Start?(7)
  4. Windows Vista Memory Requirement?(12)
  5. A Musical Tribute To Derek(5)
  6. Passwords And Short Term Memory Problems!(13)
  7. Memory Usage(5)
  8. A Good Tool To Analyse Your Pc's Memory(2)
  9. The Best Free Memory Optimizer And Manager For Windows Xp(16)
  10. In Memory Of Nirvana(6)
  11. New Laptop Vs Extra Memory(7)
  12. Help - Word2003 Insufficient Memory(4)
  13. Memory Chips(0)
  14. Genetic Memory?(9)
  15. Argh! Javascript Memory Leak!(1)


 



- Lo-Fi Version Time is now: 11th October 2008 - 03:19 AM