经过大量操作(50,000,000 次迭代)后,可用磁盘空间急剧减少
我开发了一个基准式控制台应用程序 (C# 4.0)。 50,000 或 1,000,000 次迭代运行良好。然后我将迭代计数增加到 50,000,000。但时间太长了,我强行放弃了。应用程序正常退出,但在我的主驱动器 (C:) 中只剩下 3.8 GB 可用空间。测试前可用空间为 14 GB。已经吃掉10GB了!!!请问,有人可以解释为什么会发生这种情况吗?
大家好,
我在我的项目目录中发现了 *.vsp 文件(9 GB!!!)。是的,这可能看起来很愚蠢,因为我查找了主驱动器上的每个系统|隐藏文件夹,但我从未想过这个巨大的文件可能在我的项目文件夹中。经过 50,000,000 次迭代后,我感觉我的系统变慢了,我在 VS2010 中运行 Performance Wizard。但迭代次数很少,所以我没想到性能向导可以创建如此巨大的文件!感谢大家!
I developed an benchmark-style console application (C# 4.0). Worked fine with 50,000 or 1,000,000 iterations. Then I increased a iteration count to 50,000,000. But it took too much time, and I forced it to quit. The application quitted normally, but in my main drive (C:) remained only 3.8 GB available. Before the testing free space was 14 GB. There's 10 GB has been ate !!! Please, can anybody explain why this happened?
Hi All,
I found that *.vsp file on my project directory (9 GB !!!). Yes, it may seem to be silly, because I looked up for every system|hidden folder on my main drive, but never I thought this giant file may be in my project folder. After the 50,000,000 iterations, I felt that my system got slower, and I ran Performance Wizard in VS2010. But iteration count was very little, so I did not think that performance wizard can create such a giant file! Thanks to all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果没有更多信息(比如测试实际执行的操作),我的猜测是程序像筛子一样泄漏了内存,Windows 通过不断增加交换/分页文件的大小来补偿,在此过程中耗尽了硬盘空间。您可以查看您的
C:\pagefile.sys
并查看它有多大。Without more information (like what the test actually does) my guess is that the program leaked memory like a sieve, and Windows compensated by steadily increasing the size of the swap/paging file, eating up your hard disk space in the process. You might take a look at your
C:\pagefile.sys
and see how big it is.对于原因 - 它可能取决于您的字符串操作(例如执行连接与使用 StringBuilder)。
至于空间在哪里,正如之前所说,它很可能是你的页面文件。
如果是你的页面文件,回收空间的方法是通过Windows手动将页面文件的大小调整到远低于当前值,然后重新启动。
Windows 键 + 暂停/中断,单击“高级系统设置”,在“性能”下,单击“设置...”
在出现的“性能选项”窗口中的“虚拟内存”下,单击“更改...”告诉 Windows 停止自动管理分页文件大小。单击 C: 驱动器并将其设置为比现在小得多的自定义大小(例如尝试 1024MB)。
重新启动计算机,页面文件现在应该更小。在您重新启动之前,该空间仍将被使用。
完成后,您可能希望将分页文件大小设置回由 Windows 自动管理。
如果您需要一些帮助来避免导致相同问题的代码,您可能需要提供一些代码片段。
For the why - it could depend on your string operations (for example performing concatenation vs. using StringBuilder).
As for where the space is, as stated before it's likely to be your page file.
If it is your page file, the way to reclaim the space is to manually adjust the size of the page file to a much lower than current value via Windows and then reboot.
Windows key + Pause/Break, click Advanced System Settings, under Performance, click Settings...
In the resulting Performance Options window, under Virtual memory, click Change... Tell Windows to stop automatically managing paging file size. Click on C: drive and set it to a custom size significantly smaller than it is now (try 1024MB for example).
Reboot your machine and the pagefile should now be smaller. Until you restart, the space will still be in use.
You'll probably want to set the paging file size back to being automatically managed by Windows once done.
If you'd like some help in avoiding the code causing the same problem, you might need to provide some code snippets.
我猜这是因为虚拟内存交换页面增加了,因为 GC 没有在迭代循环中运行,并且内存使用量增加,然后最终内存被交换到页面文件。有关控制台中 GC 的详细信息,请参阅 http://support.microsoft.com/kb/828988应用。我从未尝试过,但我认为使用
MTAThread
属性会有所帮助。I guess that's because virtual memory swap page increased, because GC was not running in your iteration loop and the memory usage increasing and then eventually memory got swapped to page file. See http://support.microsoft.com/kb/828988 for more information about GC in console application. I never tried that but I think using
MTAThread
attribute would help.交换空间(虚拟内存)的临时文件。
您的应用程序会创建文件吗?它使用了多少内存(任务管理器)?
Temporary Files of Swap Space (Virtual Memory).
Does your app create files? How much memory does it use (Task manager)?