1.虛擬機棧(本地變量表)引用的對象java
常說的GC(Garbage Collector) roots,特指的是垃圾收集器(Garbage Collector)的對象,GC會收集那些不是GC roots且沒有被GC roots引用的對象。bootstrap
一個對象能夠屬於多個root,GC root有幾下種:數據結構
java.lang.Class
實例以其它的某種(或多種)方式成爲roots,不然它們並非roots,.如下是一張由Java Profiler的標示出哪些是GC roots的示例圖:ide
做者:RednaxelaFX
連接:https://www.zhihu.com/question/53613423/answer/135743258
來源:知乎
著做權歸做者全部,轉載請聯繫做者得到受權。學習
以前看深刻理解JVM這本書,對裏面的GC ROOT的真實含義不是太清楚,網上查了一大堆資料都沒有說的很清楚,下面這是從知乎大神上看到的,這裏面記錄一下,和你們一塊兒學習this
Garbage Collection Roots A garbage collection root is an object that is accessible from outside the heap. The following reasons make an object a GC root: System Class Class loaded by bootstrap/system class loader. For example, everything from the rt.jar like java.util.* . JNI Local Local variable in native code, such as user defined JNI code or JVM internal code. JNI Global Global variable in native code, such as user defined JNI code or JVM internal code. Thread Block Object referred to from a currently active thread block. Thread A started, but not stopped, thread. Busy Monitor Everything that has called wait() or notify() or that is synchronized. For example, by calling synchronized(Object) or by entering a synchronized method. Static method means class, non-static method means object. Java Local Local variable. For example, input parameters or locally created objects of methods that are still in the stack of a thread. Native Stack In or out parameters in native code, such as user defined JNI code or JVM internal code. This is often the case as many methods have native parts and the objects handled as method parameters become GC roots. For example, parameters used for file/network I/O methods or reflection. Finalizable An object which is in a queue awaiting its finalizer to be run. Unfinalized An object which has a finalize method, but has not been finalized and is not yet on the finalizer queue. Unreachable An object which is unreachable from any other root, but has been marked as a root by MAT to retain objects which otherwise would not be included in the analysis. Java Stack Frame A Java stack frame, holding local variables. Only generated when the dump is parsed with the preference set to treat Java stack frames as objects. Unknown An object of unknown root type. Some dumps, such as IBM Portable Heap Dump files, do not have root information. For these dumps the MAT parser marks objects which are have no inbound references or are unreachable from any other root as roots of this type. This ensures that MAT retains all the objects in the dump 做者:秦漢郵俠 連接:https://www.jianshu.com/p/f4ff9fcc0759 來源:簡書 簡書著做權歸做者全部,任何形式的轉載都請聯繫做者得到受權並註明出處。
參考:spa
https://www.jianshu.com/p/f4ff9fcc0759線程