为什么不卸载类加载器就不能卸载类? [英] Why can a class not be unloaded without unloading the classloader?

查看:43
本文介绍了为什么不卸载类加载器就不能卸载类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中卸载类的答案说-

可以卸载类的唯一方法是,如果使用的类加载器是垃圾回收。
我看了 JLS 但无法理解

"The only way that a Class can be unloaded is if the Classloader used is garbage collected." I took a look at the JLS but couldn't understand it

为什么会这样?

推荐答案

仅当类被垃圾回收时,该类才被卸载,为此,在任何地方都不能引用该类。并且类加载器会保留对其加载的每个类的引用。

A class is only unloaded when it is garbage collected, and for that to happen there must be no references to it anywhere. And the classloader keeps a reference to each class it loads.

这篇关于为什么不卸载类加载器就不能卸载类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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