BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / java / #42262同步于 2015/6/30
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖

jvm垃圾回收机制的一个疑问关于gc root。

superzhaoyy
2015/6/30镜像同步7 回复
There are several kinds of GC roots. One object can belong to more than one kind of root. The root kinds are: oClass - class loaded by system class loader. Such classes can never be unloaded. They can hold objects via static fields. Please note that classes loaded by custom class loaders are not roots, unless corresponding instances of java.lang.Class happen to be roots of other kind(s). oThread - live thread oStack Local - local variable or parameter of Java method oJNI Local - local variable or parameter of JNI method oJNI Global - global JNI reference oMonitor Used - objects used as a monitor for synchronization oHeld by JVM 这些为gc root,垃圾回收根对象,按照文档说法是这些根对象不会被gc回收。 那么如果 ArrayList a= new ArrayList(); a=null; 这个new出来的ArrayList会被回收吧,但是ArrayList满足上面gc根对象的第一条啊。 可能理解有误,求教指点迷津。
订阅后,新回复会通过你的通知中心匿名送达。
7 条回复
icyfox机器人#1 · 2015/6/30
第一条说的好像是那个类?而不是那个对象吧?
weiqi1028机器人#2 · 2015/6/30
我觉得第一条是说作为 system class loader 载入的类的 objects 的 static fields 可以加入 gc roots. 因为这部分 static fields 是存在方法区中的
tdanieln机器人#3 · 2015/7/1
对象的引用应该是创建在栈上的,引用的内容是在堆上的,如果对上的内容没有被栈上的内容引用,jvm好像就会回收堆上的内容。@nuanyangyang 求暖神解惑
nuanyangyang机器人#4 · 2015/7/1
【 在 superzhaoyy 的大作中提到: 】 : There are several kinds of GC roots. One object can belong to more than one kind of root. The root kinds are: : oClass - class loaded by system class loader. Such classes can never be unloaded. They can hold objects via static fields. Please note that classes loaded by custom class loaders are not roots, unless corresponding instances of java.lang.Class happen to be roots of other kind(s). : oThread - live thread : ................... 第一条说的是class本身,也就是ArrayList.class,而不是你new出来的实例。 那个a是局部变量。
HBYRQ机器人#5 · 2015/7/1
oStack Local - local variable or parameter of Java method 请问第二条指的是不是方法体内的局部变量不会被gc掉,等它生命周期结束自动出栈? 【 在 nuanyangyang (暖羊羊) 的大作中提到: 】 : 第一条说的是class本身,也就是ArrayList.class,而不是你new出来的实例。 : 那个a是局部变量。 通过『我邮2.0』发布
nuanyangyang机器人#6 · 2015/7/1
【 在 HBYRQ 的大作中提到: 】 : oStack Local - local variable or parameter of Java method : 请问第二条指的是不是方法体内的局部变量不会被gc掉,等它生命周期结束自动出栈? : : ................... 嗯。确切地说,是局部变量指向的对象。
HBYRQ机器人#7 · 2015/7/1
谢谢 理解啦 【 在 nuanyangyang (暖羊羊) 的大作中提到: 】 : 嗯。确切地说,是局部变量指向的对象。 通过『我邮2.0』发布