Tech Off Thread

13 posts

Minimize Window Drop it's Mem Usage

Back to Forum: Tech Off
  • User profile image
    ido.ran

    Hi, I have a question bug me for long time:
    Open Task Manager and locate process of application which take more than 100MB of memory (under Mem Usage column), like Visual Studio or Internet Explorer.
    Now, while keep Task Manager open and visible minimize the application, watch the Mem Usage drop suddenly to about 15MB and then start climbing.

    The question is Why? Why does this happen and where is all the memory the application suddenly go?
    I have Windows XP SP 3, I must say that under Vista I didn't saw the same behavior.

    Thank you,
    Ido.

  • User profile image
    Sven Groot

    What Task Manager shows as an application's memory usage is actually its working set. Windows trims the working set of an application when it is minimized, so that's why this figure goes down. The working set is not an accurate representation of how much memory an application is using.

    In Windows Vista, Microsoft modified Task Manager to show private bytes instead (which is a much more useful figure), so this phenomenon doesn't occur anymore.

  • User profile image
    spivonious

    Just to add...I believe XP copies a minimized app's memory to the page file, which explains the drop in memory usage in Task Manager.

  • User profile image
    Yggdrasil

    Sven Groot said:

    What Task Manager shows as an application's memory usage is actually its working set. Windows trims the working set of an application when it is minimized, so that's why this figure goes down. The working set is not an accurate representation of how much memory an application is using.

    In Windows Vista, Microsoft modified Task Manager to show private bytes instead (which is a much more useful figure), so this phenomenon doesn't occur anymore.

    To clarify Sven's answer - the working set value that you see in TaskMan is the memory that the app requested, not the memory that it necessarily allocated, or is using. Even if you don't minimize, this unused memory in the working set will be released, if a different app asked for it.

  • User profile image
    mfreidge

    Sven Groot said:

    What Task Manager shows as an application's memory usage is actually its working set. Windows trims the working set of an application when it is minimized, so that's why this figure goes down. The working set is not an accurate representation of how much memory an application is using.

    In Windows Vista, Microsoft modified Task Manager to show private bytes instead (which is a much more useful figure), so this phenomenon doesn't occur anymore.

    I am confused with your answer. If I click "minimize" icon for Visual Studio, does the actual memory released (because Windows trims the working set)? Or TaskMan lies and the same huge memory is consumed by VS?

  • User profile image
    figuerres

    mfreidge said:
    Sven Groot said:
    *snip*
    I am confused with your answer. If I click "minimize" icon for Visual Studio, does the actual memory released (because Windows trims the working set)? Or TaskMan lies and the same huge memory is consumed by VS?
    xp and vista show a different number.

    both are "right"

    Winodws like other systems uses Virtual Memory, multi taksing, and all apps request virtual memory which the OS can re-map from ram to disk. the OS can also ask running apps to "give up" address space to make room for other apps or system tasks.

    .Net apps have a runtime that gets ram from the OS in big chunks so that it makes less calls to the OS.

    native apps also use this kind of logic cause every time your app calls the OS that makes for overhead / slows down your app if you do that to much. also grabbing a large chunk keeps memory pages more "local" to the app and less fragmented.
    that also leads to better perf.

    but all of this means that an app may have asked for say 1 gig of ram but only "need" 300K right now.
    when a window is minimised the OS asks it to please free any extra memory.

    I think that goes way back to old windows when we had less ram and this was even more important, but that's just my thinking and may not be true.

    in any case when an app gets that request it can check and see that it can free some ram and does so.

    thus the shrinking.

    in XP you did not see this due to the way the xp task manager selected the numbers to show.

    but yes xp did the same thing.

  • User profile image
    evildictait​or

    mfreidge said:
    Sven Groot said:
    *snip*
    I am confused with your answer. If I click "minimize" icon for Visual Studio, does the actual memory released (because Windows trims the working set)? Or TaskMan lies and the same huge memory is consumed by VS?
    You are thinking of "memory" as a single concept. In modern operating systems a distinction is made between "logical memory" which is what the program thinks it can access and "physical memory" which is data stored in your computer's RAM. The difference between these two values comes from the fact that the operating system can move data out of RAM and onto disk so other programs can use that RAM.

    When you minimise your program, you find that Windows no longer prioritises the program for "physical memory", and so a greater proportion of its memory lies on disk. This means that the program will run slower, but other programs running at the same time will run faster (because more of their memory can lie in RAM).

    The rationale here is that if you can see a program/window, you probably care more about it's responsiveness.

  • User profile image
    littleguru

    evildictaitor said:
    mfreidge said:
    *snip*
    You are thinking of "memory" as a single concept. In modern operating systems a distinction is made between "logical memory" which is what the program thinks it can access and "physical memory" which is data stored in your computer's RAM. The difference between these two values comes from the fact that the operating system can move data out of RAM and onto disk so other programs can use that RAM.

    When you minimise your program, you find that Windows no longer prioritises the program for "physical memory", and so a greater proportion of its memory lies on disk. This means that the program will run slower, but other programs running at the same time will run faster (because more of their memory can lie in RAM).

    The rationale here is that if you can see a program/window, you probably care more about it's responsiveness.
    ... as long as you don't switch to "give background processes higher priority" in the windows settings. A nice switch for servers.

    But it makes a lot of sense to page out the physical memory for apps that run minimized on a desktop system.

    It's interesting how many people get fooled by the numbers in the task manager. There are threads in various forums where people think that minimizing reduces the footprint etc. You got to love these "tweaks" Tongue Out

  • User profile image
    figuerres

    littleguru said:
    evildictaitor said:
    *snip*
    ... as long as you don't switch to "give background processes higher priority" in the windows settings. A nice switch for servers.

    But it makes a lot of sense to page out the physical memory for apps that run minimized on a desktop system.

    It's interesting how many people get fooled by the numbers in the task manager. There are threads in various forums where people think that minimizing reduces the footprint etc. You got to love these "tweaks" Tongue Out
    yeah I think I have seen at least 10 times where folks
    a) think they have a memory leak
    b) think the app is using to much ram
    c) think they need to start doing a GC in thier code
    d) generaly just do not have a clue how modern OS's manage memory and VM address space.
    e) they think that they know more than the guys who wrote the MM systems .... and want to "do it better"
    f)  pick any of the above in whatever set you want...

    Smiley


  • User profile image
    evildictait​or

    figuerres said:
    littleguru said:
    *snip*
    yeah I think I have seen at least 10 times where folks
    a) think they have a memory leak
    b) think the app is using to much ram
    c) think they need to start doing a GC in thier code
    d) generaly just do not have a clue how modern OS's manage memory and VM address space.
    e) they think that they know more than the guys who wrote the MM systems .... and want to "do it better"
    f)  pick any of the above in whatever set you want...

    Smiley


    I have a GC in my code. Does that make me a bad person?

  • User profile image
    figuerres

    evildictaitor said:
    figuerres said:
    *snip*
    I have a GC in my code. Does that make me a bad person?

    lol, only if you fall into the case we are talking about, using it for the wrong reason, thinking that minimising the window is important in how much memory your apps use etc.... I suspect you are slightly smarter than all that...

    any tool has it's proper use.

    but using a hammer on the wrong thing tends to have bad results sooner or later Smiley

  • User profile image
    littleguru

    evildictaitor said:
    figuerres said:
    *snip*
    I have a GC in my code. Does that make me a bad person?
    Yes. Wink

  • User profile image
    evildictait​or

    littleguru said:
    evildictaitor said:
    *snip*
    Yes. Wink
    But how else am I supposed to release memory from dead objects in my programs? Do you really expect me to remember where to put the deletes in my program? That's way too much effort.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.