你如何保护自己失控的内存消耗带来在PC?保护自己、消耗、内存、PC

2023-09-03 12:13:31 作者:封心锁爱只为等一人

每一个现在,我又发现自己做一些适度愚蠢的结果在我的程序分配所有的内存就可以得到,然后一些。

Every now and again I find myself doing something moderately dumb that results in my program allocating all the memory it can get and then some.

这种用来使程序与内存不足的错误相当快死的事情,但这些天的Windows会走出它的方式给这个不存在的内存给应用程序,而实际上是显然$ ppared自杀做因此P $。不是字面上的过程,但它会饿死本身的可用物理RAM如此糟糕,即使在运行任务管理器需要一个半小时换的(毕竟失控的应用程序仍在分配越来越多的内存所有的时间)。

This kind of thing used to cause the program to die fairly quickly with an "out of memory" error, but these days Windows will go out of its way to give this non-existent memory to the application, and in fact is apparently prepared to commit suicide doing so. Not literally of course, but it will starve itself of usable physical RAM so badly that even running the task manager will require half an hour of swapping (after all the runaway application is still allocating more and more memory all the time).

这不会发生太频繁,但它确实是灾难性的。我通常有重置我的机器,从而导致数据丢失,不时和一般的诸多不便。

This doesn't happen too often, but when it does it's disastrous. I usually have to reset my machine, causing data loss from time to time and generally a lot of inconvenience.

你对制作这样一个错误的后果那么可怕任何实际的建议?也许某些注册表调整将虚拟内存限制的应用程序,允许分配的最大金额?或者一些CLR标记,这将限制这种只对当前应用程序? (它通常是在.NET中,我这样做是为了我自己。)

Do you have any practical advice on making the consequences of such a mistake less dire? Perhaps some registry tweak to limit the max amount of virtual memory an app is allowed to allocate? Or some CLR flag that will limit this only for the current application? (It's usually in .NET that I do this to myself.)

(不要用完的RAM和买更多的内存的是没有用的 - 前者我无法控制,而后者我已经已经完成了。)

("Don't run out of RAM" and "Buy more RAM" are no use - the former I have no control over, and the latter I've already done.)

推荐答案

您可以当你运行一个应用程序的风险保持在命令提示符下打开。然后,如果它开始变得失控,你不必等待任务管理器来加载,只需使用:

You could keep a command prompt open whenever you run a risky app. Then, if it starts to get out of control, you don't have to wait for Task Manager to load, just use:

taskkill /F /FI "MEMUSAGE ge 2000000"

这将(理论上),力比2GB的内存使用更多的杀死任何东西。

This will (in theory) force kill anything using more than 2GB of memory.

使用 TASKKILL /?来获得期权所花费的完整列表。

Use taskkill /? to get the full list of options it takes.

编辑:更妙的是,运行命令计划任务每​​隔几分钟。启动炸毁任何过程中会得到自动手段传给。

Even better, run the command as a scheduled task every few minutes. Any process that starts to blow up will get zapped automatically.