希望这有帮助 Jay " LP" ; < [email protected]>写在消息 新闻:Oq ************** @ TK2MSFTNGP09.phx.gbl ...考虑下面的代码。它会让GC真正收集吗?一个应用程序在循环中从第三方程序集创建一个类的新实例(它具有)。那个班没有。目的或任何类似的方法。我想使确保GC跟上循环。我的推理是否调用了Thread.Sleep(1000); GC会优先考虑它的工作,对吗? GC.Collect(); GC.WaitForPendingFinalizers(); System.Threading.Thread.Sleep(1000);Just remember that "the collector is self-tuning so don''t mess with it"!Hope this helpsJay"LP" <[email protected]> wrote in messagenews:Oq**************@TK2MSFTNGP09.phx.gbl... Hi, Considering code below. Will it make GC to actually collect. One application creates new instances of a class from 3rd party assembly in a loop (it has to). That class doesn''t have .Dispose or any similar method. I want to make sure GC keeps up with the loop. My reasoning if Thread.Sleep(1000) is called; GC will take priority it do its work, right? GC.Collect(); GC.WaitForPendingFinalizers(); System.Threading.Thread.Sleep(1000); 这篇关于此代码强制垃圾收集器收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-27 08:23