CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2007
    Posts
    102

    Question Memory leak or not memory leak?

    Hi!

    I currently looking for memory leak in my application. After I found out one operation that seems to make a memory leak from the task manager, I decided to test one thing (since I know I can't trust the task manager information).

    I created 3 small windows applications by using the project wizard of visual studio 2008, using default settings.

    In the first application, I do nothing else, just run it - pretty simple.

    In the second application, I just add at the end of the "InitInstance" member function of my class application the following lines:
    BYTE **up_info = new BYTE *[80000];
    for (int i=0; i<80000; i++) up_info[i] = new BYTE[512];
    for (int i=0; i<80000; i++) delete[] up_info[i];
    delete[] up_info;

    In the third application, I did the same thing than for the second application with adding a loop on this memory allocation/deallocation a big number of time.

    I believe that my code does not have memory leak. Tell me if I am wrong.
    After the memory allocation/desallocation has been finished for each of the 3 applications, I checked the memory information through the Process Explorer application.
    Here are the information:

    Type of memory / First Application / Second Application / Third Application
    Working set / 15,584 K / 19,180 K / 50,324 K
    WS Private / 3,428 K / 7,020 K / 38,152 K
    WS Shareable / 12,156 K / 12,160 K / 12,172 K
    WS Shared / 10,912 K / 10,896 K / 10,912 K
    Private Bytes / 4,632 K / 8,160 K / 39,408 K
    Virtual Size / 118,644 K / 165,364 K / 197,748 K
    Peak Private Bytes / 8,688 K / 47,580 K / 49,412 K
    Peak Working set / 19,572 K / 55,896 K / 57,396 K

    In case of the third application, the memory is increasing until stabilizing to a certain value. I stopped the loop when the memory usage was stable in the Task manager.

    So here are my questions:
    Since I truely believe that my code doesn't generate memory leaks, why does the private bytes has increased so much in the case of the third application?
    How can I read all theses memory values to determine whether I have a memory leak or not?
    During the loop of the third application, the number of page fault is increasing a lot. Why?

    Thanks for you time,

    madric

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Memory leak or not memory leak?

    No, that code doesn't have memory leaks. If you want memory leak reports, use a specialized tool, not task manager or PE.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Feb 2007
    Posts
    102

    Re: Memory leak or not memory leak?

    So why the private bytes is over 38MB for the third application?
    And what specialized tool should I use?

  4. #4
    Join Date
    Feb 2005
    Location
    Pune (India)
    Posts
    644

    Thumbs up Re: Memory leak or not memory leak?

    "Devise the simplest possible solution that solves the problems"

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Memory leak or not memory leak?

    Quote Originally Posted by madric View Post
    So why the private bytes is over 38MB for the third application?
    And what specialized tool should I use?
    There are commercial tools and also free tools. I've used this Visual Leak Detector several times.

    http://dmoulding.googlepages.com/vld
    http://www.codeproject.com/KB/applic...kdetector.aspx
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Feb 2007
    Posts
    102

    Re: Memory leak or not memory leak?

    ok thanks, I will look into those softwares.
    But, just wonder...
    There is no way to know how much memory my application has really allocated from all the statistics given from Process Explorer?

  7. #7
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Memory leak or not memory leak?

    You should think of the virtual memory footprint in PE as sort of an approximate "peak memory used at once" measure for the program. There's not a whole lot of reason for that to get smaller when actual usage decreases (although it sometimes may). Plus there are behind-the-scenes OS factors which may jiggle the numbers around a bit. So no, in exact terms, you can't rely on PE for much of anything except detecting whether you're leaking memory like a sieve.

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