Memory leak

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dariophoenix
    New Member
    • Oct 2006
    • 34

    Memory leak

    Hi,
    I have a program which runs fine and has no leaks. But if I add this line...

    map <long, NetworkComponen t> network;

    ... right before the main's() final return, it runs fine but Valgrind (I'm using KDevelop) tells me there is a memory leak. How can it be, if I haven't inserted anything in the map, and network is stored in the stack and thus needs not be deleted?
    Thanks for the attention
  • dariophoenix
    New Member
    • Oct 2006
    • 34

    #2
    I'm not using pointers nor creating objects on the heap... Then

    a) A map needs to be cleaned up explicitly. So I added the line:
    network.clear() ;
    but the leak is still there. Is there any other way to clean up a map?

    b) Valgrind is wrong

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      From you description I see no reason why you should get a memory leak although the code may be more informative.

      Comment

      • dariophoenix
        New Member
        • Oct 2006
        • 34

        #4
        Hi, thanks for answering. I created a new project with just this code, and I still get a memory leak:

        [CODE]
        // test.cpp
        #include <map>
        #include <string>
        using namespace std;

        int main(int argc, char* argv[]){

        map <long, string> s;
        s.clear();
        return 0;
        }
        [\CODE]

        Comment

        Working...