|
-
April 17th, 2007, 04:31 AM
#1
memleak in map
Code:
#include <iostream>
#include <map>
using namespace std;
int main()
{
map < int , string > sampMap;
map < int , string > sampMap1;
sampMap[1] = "Adams";
sampMap[2] = "Peter";
map < int , map< int , string >> tempMap;
tempMap[1] = sampMap;
sampMap1 = tempMap[1];
sampMap1[3] = "Thomson";
tempMap[1] = sampMap1;
}
Will this program cause any memory leak?
As we are assigning( over writing ) sampMap1 to tempMap[1], will the tempMap loose the reference of sampMap and produce any memory leak?
-
April 17th, 2007, 04:38 AM
#2
Re: memleak in map
 Originally Posted by adapanaidu
Will this program cause any memory leak?
No.
Regards,
Laitinen
-
April 17th, 2007, 04:49 AM
#3
Re: memleak in map
Memory leaks can only be created when allocating memory from the heap. Since you don´t do that and map is assumed not to create any leaks, there will be no memory leaks.
Regards,
Guido
- Guido
-
April 17th, 2007, 06:00 AM
#4
Re: memleak in map
The map class and the string class automatically free the memory they use.
-
April 18th, 2007, 07:04 AM
#5
Re: memleak in map
Thank U Guys.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|