CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: memleak in map

  1. #1
    Join Date
    Mar 2006
    Location
    Inida
    Posts
    119

    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?

  2. #2
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  3. #3
    Join Date
    Nov 2006
    Location
    Essen, Germany
    Posts
    1,344

    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

  4. #4
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Thumbs up Re: memleak in map

    The map class and the string class automatically free the memory they use.
    My hobby projects:
    www.rclsoftware.org.uk

  5. #5
    Join Date
    Mar 2006
    Location
    Inida
    Posts
    119

    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
  •  





Click Here to Expand Forum to Full Width

Featured