.NET垃圾回收工作不正常吗?不正常、垃圾、工作、NET

2023-09-04 00:46:03 作者:我愿溺死你海@

我们已经在.NET 4.0上运行的图像转换脚本,IIS 7,ASP.NET,4 GB内存的服务器调整大小的图像大,因此需要大量的内存。

We had an image conversion script running on .NET 4.0, IIS 7, ASP.NET, 4 GB server RAM that resizes large images and thus needs a lot of memory.

第一个脚本增加的内存使用率几乎为100%,剩下几乎没有为SQL Server还运行(这给了内存,直到20 MB,而不是通常的900 MB运行)。

The first script increased memory usage to almost 100%, leaving virtually nothing for the SQL Server that was also running (which gave up memory until running on 20 MB instead the usual 900 MB).

在第二个脚本中,我们增加了一个GC.Collect的()和(可以肯定的),每个周期结束后一秒钟线程睡觉,一切都恢复正常了。

In the second script we added a GC.Collect() and (to be sure) a one sec thread sleep after each cycle, and everything went back to normal.

问:是不是在.NET内存管理的一个漏洞?如果不是系统仔细看看发生了什么事的可用内存,放慢改革的步伐和清理?

Question: isn't that a flaw in the .NET memory management? Shouldn't the system take a closer look at what's happening with the available memory, slow things down and clean up?

推荐答案

根据该的文档:

垃圾收集情况   当一个请求自动   存储器不能使用满足   可用内存。

Garbage collection happens automatically when a request for memory cannot be satisfied using available free memory.

我认为这种情况已经不能够满足作为SQL Server的支持下代替。至于它是一个错误;该文档建议这是由设计。

I assume this situation hasn't been satisfied as SQL Server is backing down instead. As for it being a bug; the docs would suggest this is by design.