且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

强制垃圾收集在C#中的***实践

更新时间:2022-11-09 08:27:32

***的做法是不强制进行垃圾回收。

The best practise is to not force a garbage collection.

根据MSDN:

这是可以强制垃圾   收集致电收集,但   大部分时间,这应该是   避免,因为它可能会产生   性能问题。

"It is possible to force garbage collection by calling Collect, but most of the time, this should be avoided because it may create performance issues. "

不过,如果你能可靠地测试您的code,以确认调用收集()将不会有负面影响,然后继续前进......

However, if you can reliably test your code to confirm that calling Collect() won't have a negative impact then go ahead...

只是尽量确保物品被清理,当你不再需要它们。如果你有自定义对象,看看使用了使用说明和IDisposable接口。

Just try to make sure objects are cleaned up when you no longer need them. If you have custom objects, look at using the "using statement" and the IDisposable interface.

该环节与方面一些好的实用的建议,以释放内存/垃圾收集等:

This link has some good practical advice with regards to freeing up memory / garbage collection etc:

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