java - HashMap算不算GCRoot?
巴扎黑
巴扎黑 2017-04-18 10:19:45
0
1
447

在看MAT得时候,看到关于GCRoot的定义中有一条:

  • 系统类或者说是由系统类加载器加载的类。

HashMap位于java.util包下,由BootstrapClassLoader加载,那么它是不是GCRoot呢?

如果是的话,我还有一个疑问,想请教:如果HashMap是GCRoot,那么它内部存储的对象肯定包含在GCRoot引用链的了,那么每次在垃圾回收器回收的时候HashMap中的对象都无法被回收掉,那这样岂不是造成内存泄露了?

巴扎黑
巴扎黑

reply all (1)
PHPzhong

GC Roots include:

  1. Variables in the virtual machine stack.

  2. Constants in the method area.

  3. Static variables in the method area.

At the same time, it is necessary to clarify that Java memory is roughly divided into: virtual machine stack, Native method stack, Java heap, local program counter and method area. A HashMap reference can be used as a GC Root, but the HashMap entity is not a GC Root.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!