Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对类加载过程的补充 #662

Closed
guang19 opened this issue Feb 28, 2020 · 1 comment
Closed

对类加载过程的补充 #662

guang19 opened this issue Feb 28, 2020 · 1 comment
Labels
awesome enhancement New feature or request or suggestion

Comments

@guang19
Copy link
Contributor

guang19 commented Feb 28, 2020

image

类的生命周期:
加载 -->连接-->初始化-->使用-->卸载

其中连接又可细分为: 验证,准备,解析三个阶段。

加载,连接,初始化老哥都已经写了。我想补充下卸载阶段:

卸载类

卸载类即该类的Class对象被GC。

卸载类需要满足3个要求:

  1. 该类的所有的实例对象都已被GC,也就是说堆不存在该类的实例对象。
  2. 该类没有在其他任何地方被引用
  3. 该类的类加载器的实例已被GC

所以,在JVM生命周期类,由jvm自带的类加载器加载的类是不会被卸载的。但是由我们自定义的类加载器加载的类是可能被卸载的。

只要想通一点就好了,jdk自带的BootstrapClassLoader,PlatformClassLoader,AppClassLoader负责加载jdk提供的类,所以它们(类加载器的实例)肯定不会被回收。而我们自定义的类加载器的实例是可以被回收的,所以使用我们自定义加载器加载的类是可以被卸载掉的。

@Snailclimb
Copy link
Owner

Snailclimb commented Feb 29, 2020

赞啊!老哥!感谢老哥提出来。当时我可能觉得卸载不属于类加载里面的就没加。我等下补充上去作为拓展。

已经补充!地址:

https://github.com/Snailclimb/JavaGuide/blob/master/docs/java/jvm/%E7%B1%BB%E5%8A%A0%E8%BD%BD%E8%BF%87%E7%A8%8B.md

Screen Shot 2020-02-29 at 8 45 22 PM

@Snailclimb Snailclimb added awesome enhancement New feature or request or suggestion labels Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awesome enhancement New feature or request or suggestion
Projects
None yet
Development

No branches or pull requests

2 participants