在哪种情况下,我们必须调用垃圾收集器 [英] In which situation we have to call the Garbage collector

查看:54
本文介绍了在哪种情况下,我们必须调用垃圾收集器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪种情况下我们必须明确地调用垃圾收集器

In which situation we have to call the Garbage collector explicitly

推荐答案

几乎没有。

最佳做法是不要强迫垃圾收集。



根据 MSDN [ ^ ]



可以通过调用Collect来强制进行垃圾收集,但大部分时间都应该避免这种情况,因为它可能会产生性能问题。



您应该改为实现Destructors或IDisposable并在类实例上使用Dispose。
Almost none.
The best practise is to not force a garbage collection.

According to 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. "

You should instead implement Destructors or IDisposable and use Dispose on your class instances.


在极少数情况下可以完成。就像你想要释放你的程序使用的内存,以使你的程序更好地执行。
In very few situations it can be done.Like you want to free up your program used memory in order to make your performance of your program more.


这篇关于在哪种情况下,我们必须调用垃圾收集器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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