什么时候.NET垃圾收集器运行? [英] When does the .net garbage collector run?

查看:108
本文介绍了什么时候.NET垃圾收集器运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调试.NET code,我怎么能知道垃圾收集器运行时?

When I debug .net code, how can I know when the garbage collector runs?

我不希望控制垃圾收集器运行时。我只希望能够被运行时,就知道了。我有一个是资源耗尽某些code。我知道资源未被使用;我想,当GC运行释放他们就知道了。

I do not wish to control when the garbage collector runs. I only wish to be able to know when it is running. I have some code that is running out of resources. I know that the resources are not being used; I want to know when the GC is running to free them.

呵呵,和我心目中的资源是从SQL连接池的连接,而不是记忆: - )

Oh, and the resources I have in mind are connections from a Sql connection pool, not memory :-)

推荐答案

您必须使用.NET 4.0,你要求的是不支持早期的教版本。什么

You have to use .NET 4.0, what you are asking for isn't supported in eariler versions.

实际上调用WaitForFullGCApproach,并在循环中WaitForFullGCComplete方法。 WaitForFullGCApproach将阻塞,直到你看到一个GC,WaitForFullGCComplete将阻塞,直到GC完成。

Essentially you call the WaitForFullGCApproach and the WaitForFullGCComplete methods in a loop. WaitForFullGCApproach will block until you see a GC, WaitForFullGCComplete will block until the GC is complete.

请仔细阅读这篇文章。如果您使用此方法,那么你有责任makign确保垃圾收集实际发生。如果你搞砸了,你可能会破坏GC并迅速耗尽内存。

Please read this article carefully. If you use this method then you are responsible for makign sure the garbage collection actually occurs. If you mess this up you could break the GC and quickly run out of memory.

http://msdn.microsoft.com/en-us/library/ cc713687.aspx

这篇关于什么时候.NET垃圾收集器运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆