gpt4 book ai didi

.net - Application.ThreadException : memory leak if not detached?

转载 作者:行者123 更新时间:2023-12-04 07:27:37 24 4
gpt4 key购买 nike

Application.ThreadException的reference page

Because this is a static event, you must detach your event handlers when your application is disposed, or memory leaks will result.



尽管该页面上的示例代码并未分离事件处理程序,但如果未分离事件处理程序,它是否真的泄漏了?

似乎只有当应用程序关闭时,才应该分离处理程序。在那种情况下,无论处理程序是否已分离,应用程序使用的所有内存都将被释放?

最佳答案

这可能很不常见,但是由于某些原因,WinForms应用程序的Main()方法可能看起来像这样:

static bool AbortStartup { get; set; }

[STAThread]
public static void Main()
{
Application.Run(new CancelableSplashScreen());

if (!AbortStartup)
Application.Run(new MainWindow());
}

当初始屏幕关闭时,将显示主窗口,除非初始屏幕将 AbortStatup属性设置为 true。如果您在初始屏幕中将事件处理程序添加到 Application.ThreadException中,则在应用程序终止之前, CancelableSplashScreen的实例将不会被垃圾收集,这可能是相当长的时间。

关于.net - Application.ThreadException : memory leak if not detached?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7812627/

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