gpt4 book ai didi

.net - .NET 中 GC.WaitForPendingFinalizers() 在什么情况下会阻塞?

转载 作者:行者123 更新时间:2023-12-03 12:56:30 25 4
gpt4 key购买 nike

引用来自 GC.WaitForPendingFinalizers() 的 MSDN 文档:

The thread on which finalizers are run is unspecified, so there is no guarantee that this method will terminate.



我真的不明白这句话。这个方法在什么情况下不会终止?这与终结器运行的线程有什么关系?为什么他们说线程是“未指定的”?

关于终结器线程,我认为以下是正确的(?):
  • 只有一个终结器线程。
  • 终结器始终在单独的线程上运行(即从不在主线程或任何其他用户创建的线程上)。

  • 注意:我可以想象当终结器之一阻塞时,此方法会阻塞,但无论终结器使用什么线程,都存在此问题。

    最佳答案

    来自 another article on MSDN :

    The Finalize method might not run to completion or might not run at all in the following exceptional circumstances:

    • Another finalizer blocks indefinitely (goes into an infinite loop, tries to obtain a lock it can never obtain and so on). Because the runtime attempts to run finalizers to completion, other finalizers might not be called if a finalizer blocks indefinitely.

    • The process terminates without giving the runtime a chance to clean up. In this case, the runtime's first notification of process termination is a DLL_PROCESS_DETACH notification.

    关于.net - .NET 中 GC.WaitForPendingFinalizers() 在什么情况下会阻塞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12731280/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com