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

    MFC App & Physical Memory

    Hello there,

    I have a MFC app developed in VS 2012. Inside couple of worker threads it's constantly doing bunch of things.

    Now if i start the app and then open the Task Manager and look at the Physical Memory for my app, it's constantly incriminating until i close the app.

    I didn't try to run the app for more than an hour yet, as i am not sure whether that will screw up other app's in the system.

    What does this increase in Physical Memory mean? Is this a problem?

    If yes, how can i fix that?

    Thanks in advance.

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: MFC App & Physical Memory

    What does this increase in Physical Memory mean? Is this a problem?

    If yes, how can i fix that?
    It means that the program is constantly obtaining more memory and not releasing memory it has previosuly obtained. This could be caused by repeatedly creating some new resource and not deleting a previous resource first - or allocating mmeory and not freeing it when needed.

    It is a problem and you will need to examine the program to see what is happening. There are tools available which can assist you with this.

    You haven't provided any code so can't really comment. But, for example, one issue could be creating brushes in a message handling function and not deleting them etc.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MFC App & Physical Memory

    And of course, have a look at this FAQ: How to detect memory leaks in MFC?
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  4. #4
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: MFC App & Physical Memory

    note that the item posted by Ovidiocucu only detects memory leaks caused by new/delete (getmem/freemem).

    It does not detect memory leaking through other means.

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: MFC App & Physical Memory

    Quote Originally Posted by OReubens View Post
    note that the item posted by Ovidiocucu only detects memory leaks caused by new/delete [...]
    Correct, except my nickname.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: MFC App & Physical Memory

    Quote Originally Posted by Don Guy View Post
    Inside couple of worker threads it's constantly doing bunch of things.
    You should carefully review that "doing bunch of things" regarding object allocations and deallocations. For the start you may put a breakpoint in object destructors to see if those really called and find this way the problem one.

    A special case may be COM objects not released properly.

    What does this increase in Physical Memory mean? Is this a problem?
    Yes, this is a real problem, as physical memory is a limited resource going to be exhausted sooner or later resulting in a crash or hanging up.
    Best regards,
    Igor

  7. #7
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MFC App & Physical Memory

    As stated, an increase in memory is a problem, but only if it continues forever. Leave your app for a few hours or days to see what happens. Many allocators can behave in a way that makes you think that you have a leak when you in fact don't. The reason is that it can be very beneficial in terms of performance not to deallocate memory immediately.

    I can recommend a tool called Visual Leak Detector to help you find any leaks.
    Nobody cares how it works as long as it works

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