视窗操作系统和内存管理 - 当一个应用程序被最小化,会发生什么?最小化、视窗、应用程序、内存管理

由网友(孤傲°)分享简介:我问这个问题留给后人的原因和一般的兴趣。几年前,我发现在Windows中一个奇怪的行为。我知道这个工程在XP中,并在那个时候还曾经在Windows 2000,甚至98,我会承担起这种行为仍然适用于Windows 7。I'm asking this question for posterity reasons and...

我问这个问题留给后人的原因和一般的兴趣。几年前,我发现在Windows中一个奇怪的行为。我知道这个工程在XP中,并在那个时候还曾经在Windows 2000,甚至98,我会承担起这种行为仍然适用于Windows 7。

I'm asking this question for posterity reasons and general interest. Years ago I noticed an odd behavior within Windows. I know this works in XP and at that time it also worked in Windows 2000 and even 98 and I'd assume this behavior still works for Windows 7.

要设置我的问题,试试这个实验中通过以下步骤。

To setup my question, try this experiment by following these steps.

打开任务管理器,然后导航到进程选项卡。 打开你使用,你知道占用的内存(网络浏览器应该可以正常工作)相当数量的应用程序,并查找进程中的任务管理器。 现在,打开窗,文件,网页,等等,直到您的应用程序的内存使用量使用的应用程序显著的增长。 请注意应用程序的内存使用情况,并尽量减少application--你应该看到应用程序正在使用显著降低的内存量。 最后,恢复应用程序。

还原窗口后,你应该是应用程序的内存使用情况应该秒杀一点点,但不久的一样,因为它最小化你的应用程序之前,是没有在那里。这是任何基于GUI的应用相当一致,但它肯定是更深刻的具有较大的应用程序。

After restoring the Window, you should that that the Memory Usage of the application should spike a little but no where near as much as it was before you minimized the application. This is quite consistent with any GUI based application but it is certainly more profound with larger applications.

在内部的操作系统中,哪些进程正在发生,迫使这个(假定)垃圾收集发生?此外,通过COM或部分净电话有没有办法迫使这个过程中没有最小化的应用程序?如果有,请提供源$ C ​​$ C。语言并不重要。

Internally within the OS, what process is taking place that forces this (assumed) garbage collection to take place? Furthermore, via COM or some .Net calls is there a way to force this process without minimizing an application? If so, please provide source code. The language doesn't matter.

如果你像我一样,你可以保留大量的应用程序在同一时间打开。内存使用可以爬起来......起来......起来......,你知道它之前,你需要关闭一些应用程序来释放资源。这将是很好,如果我至少可以融入我有控制机制,从操作系统类似于从上面的行使行为强制垃圾收集软件。

If you are like me, you may keep a lot of applications open at the same time. Memory usage can creep up... up... up.. and before you know it, you need to close a few applications to free resources. It would be nice if I could at least integrate into the software that I have control a mechanism to force garbage collection from the OS similar to the behavior from the exercise above.

我知道,在.net中有一个GC对象,你的愿望,你可以调用垃圾清理。它并没有,但是,似乎与存储器清理发生​​这种情况,当应用程序被最小化的性质有关。

I know that in .Net there is a GC object and you can call the garbage clean-up as you desire. It does not, however, seem to be related with the nature of the memory clean-up that happens when an application is minimized.

我希望这是一个让人摸不到头脑,而且经过多年的好奇心someone-能给我是怎么回事了良好的,技术性的解释。

I hope this is a head scratcher and that after years of curiosity that someone- can give me a good, technical explanation of what is going on.

网页文件和走向进一步下跌的兔子洞

有趣的东西已被公布为回答这个问题由Kragen&放大器;亚历克斯·K.通过阅读知识库文章他们都贴出来,我看到有还有一种方法,prevent发生这种行为。什么时候你会想prevent该寻呼的发生释放的一些例子吗?我试图通读文件,了解尽可能多的关于这个问题,我可以。很多信息是新的给我,因为我已经实现任何这种.NET应用程序中从来没有需要。考虑到用例将帮助我掌握的,为什么,当我会想避免这种情况的原因。

Interesting stuff has been posted as an answer to this question by Kragen & Alex K. Upon reading the Knowledge Base article they both posted, I see that there is also a way to prevent this behavior from happening. What are some examples of when you would want to prevent this paging freeing from taking place? I'm trying to read through the documentation to learn as much about this as I can. A lot of this information is new to me because I've never needed to implement any of this within .Net applications. Considering a use-case would help me grasp the reasoning of why and when I would want to avoid this behavior.

推荐答案

你看到这个过程的不可以垃圾收集 - Windows正在修剪工作集(即分页的内存,因为它为了释放内存的前景色应用程序到磁盘)。

The process you are seeing is not garbage collection - Windows is "trimming the working set" (i.e. paging as much memory as it can to disk) in order to free up memory for foreground applications.

有关详情请参阅以下链接:

See the following links for more information:

应用程序的工作集时,它的顶级窗口最小化修剪(KB) SetProcessWorkingSetSize函数 The working set of an application is trimmed when its top-level window is minimized (KB) SetProcessWorkingSetSize Function

的知识库文章上面链接介绍你们俩如何prevent这个自动发生(通过截获 WM_SYSCOMMAND 命令),你怎么可以明确地导致这发生在任何时间(通过调用 SetProcessWorkingSetSize )。

The KB article linked above describes both how you can prevent this from automatically happening (by intercepting the WM_SYSCOMMAND command), and how you can explicitly cause this to happen at any time (by calling SetProcessWorkingSetSize).

阅读全文

相关推荐

最新文章