Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How much memory am I really using

How much memory am I really using

Scheduled Pinned Locked Moved C / C++ / MFC
helpsysadminperformancetutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bill Wilson
    wrote on last edited by
    #1

    I have a service that appears to eat memory at a pretty steady rate. If I bring up Task Manager, I can watch the Virtual Memory (and real memory) counter climb steadily. In trying to solve the problem I used the CRT library to checkpoint the memory periodically. This technique has allowed me to find and fix several leaks. Now, however, the CRT library machines are telling me there are no more leaks, while the task manager says there are still some left (real and VM still rises steadily). Following the example in MSDN, I've declared 3 _CrtMemState variables as globals (s1, s2, s3). My app does a check point into s1 and then sets a timer. When the timer goes off, the handler executes and then does another checkpoint into s2. The two checkpoints are compared into s3 and the result reported, as usual. The report shows differences in allocated memory between s1 and s2, as you would expect. The interesting part is that none of the allocation numbers change, while the Task manager keeps saying I'm eating memory!! I know the checkpointing is working because the display shows a higher total allocations count each time. Any ideas would be appreciated. Here's the code I'm using for the checkpoints.

    // global variables
    _CrtMemState s1, s2, s3;

    // last step of initialization

    \_CrtMemCheckpoint(&s1);		
    ::SetTimer(NULL, NULL, 1, OnPollTimer ); // First polling cycle is immediate
    

    // Here's the callback code

    VOID CALLBACK OnPollTimer( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
    {

    AFX\_MANAGE\_STATE(AfxGetStaticModuleState( ));
    
    
    \_Module.m\_bProcessRunning = TRUE;
    // Kill the timer
    ::KillTimer(hwnd, idEvent);
    
    DoPollTimer();
    TRACE0(\_T("OnPollTimer 1\\r\\n"));
    

    _CrtMemCheckpoint(&s2);
    _CrtMemDifference(&s3, &s1, &s2);
    _CrtMemDumpStatistics(&s3);

    TRACE0("----------------------------------------------------------\r\n");

    ::SetTimer(NULL, NULL, g\_lPollFreqSecs \* SECOND, OnPollTimer );
    \_Module.m\_bProcessRunning = FALSE;
    

    }

    I don't have access to the server right now, so I can't provide a sample of the output. It shows some memory allocated as normal, client and CRT. The numbers don't change from one iteration to the next. Any ideas would be greatly appreciated. Thanks for the help, Bill

    T 1 Reply Last reply
    0
    • B Bill Wilson

      I have a service that appears to eat memory at a pretty steady rate. If I bring up Task Manager, I can watch the Virtual Memory (and real memory) counter climb steadily. In trying to solve the problem I used the CRT library to checkpoint the memory periodically. This technique has allowed me to find and fix several leaks. Now, however, the CRT library machines are telling me there are no more leaks, while the task manager says there are still some left (real and VM still rises steadily). Following the example in MSDN, I've declared 3 _CrtMemState variables as globals (s1, s2, s3). My app does a check point into s1 and then sets a timer. When the timer goes off, the handler executes and then does another checkpoint into s2. The two checkpoints are compared into s3 and the result reported, as usual. The report shows differences in allocated memory between s1 and s2, as you would expect. The interesting part is that none of the allocation numbers change, while the Task manager keeps saying I'm eating memory!! I know the checkpointing is working because the display shows a higher total allocations count each time. Any ideas would be appreciated. Here's the code I'm using for the checkpoints.

      // global variables
      _CrtMemState s1, s2, s3;

      // last step of initialization

      \_CrtMemCheckpoint(&s1);		
      ::SetTimer(NULL, NULL, 1, OnPollTimer ); // First polling cycle is immediate
      

      // Here's the callback code

      VOID CALLBACK OnPollTimer( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
      {

      AFX\_MANAGE\_STATE(AfxGetStaticModuleState( ));
      
      
      \_Module.m\_bProcessRunning = TRUE;
      // Kill the timer
      ::KillTimer(hwnd, idEvent);
      
      DoPollTimer();
      TRACE0(\_T("OnPollTimer 1\\r\\n"));
      

      _CrtMemCheckpoint(&s2);
      _CrtMemDifference(&s3, &s1, &s2);
      _CrtMemDumpStatistics(&s3);

      TRACE0("----------------------------------------------------------\r\n");

      ::SetTimer(NULL, NULL, g\_lPollFreqSecs \* SECOND, OnPollTimer );
      \_Module.m\_bProcessRunning = FALSE;
      

      }

      I don't have access to the server right now, so I can't provide a sample of the output. It shows some memory allocated as normal, client and CRT. The numbers don't change from one iteration to the next. Any ideas would be greatly appreciated. Thanks for the help, Bill

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      (Some of my information might be outdated...) Those routines can only check for memory managed by the C runtime library (this is where I could be wrong if they have changed how this works.) Thus, things like ATOMs, heap allocations, native WIN32 allocations, etc can all still be leaking. Are you creating a bunch of GDI objects and not properly destroying them? Tim Smith Descartes Systems Sciences, Inc.

      B 1 Reply Last reply
      0
      • T Tim Smith

        (Some of my information might be outdated...) Those routines can only check for memory managed by the C runtime library (this is where I could be wrong if they have changed how this works.) Thus, things like ATOMs, heap allocations, native WIN32 allocations, etc can all still be leaking. Are you creating a bunch of GDI objects and not properly destroying them? Tim Smith Descartes Systems Sciences, Inc.

        B Offline
        B Offline
        Bill Wilson
        wrote on last edited by
        #3

        My app is a service running on NT. It has no UI, so I don't think its a GDI leak. Do you have any suggestions on how to detect/isolate the other possiblities for leaks? I don't know how to monitor the rest of the memory usage. Thanks for the help, Bill

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups