gpt4 book ai didi

java - 常量静态字段会导致 Web 应用程序中的内存泄漏吗?

转载 作者:行者123 更新时间:2023-11-30 04:11:20 26 4
gpt4 key购买 nike

我知道静态字段会导致内存泄漏,因为它们不会被GC。

但是当有一个Web应用程序部署在容器(例如Tomcat)中时,每个应用程序都有自己的ClassLoader,并且可以取消部署。

我的问题是,垃圾收集器是否声明要卸载的类的静态成员引用的对象?

最简单的情况是单例(通过引用 self 的静态变量实现),如果应用程序取消部署,它会被 GC 吗?

最佳答案

这可能会回答您的问题:

When an app is stopped, Tomcat (even before 6.0.24) nullifies the value of all static class variables of classes loaded by the WebAppClassLoader. In some cases, it may fix a classloader leak (for example because of a custom ThreadLocal class, see above), but even if we still have a leak, it may decrease the amount of memory lost

您可以阅读更多here

干杯!!

关于java - 常量静态字段会导致 Web 应用程序中的内存泄漏吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19548466/

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