File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
src/main/java/com/chen/api/util/jvm/chapter3 Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .chen .api .util .jvm .chapter3 ;
2
2
3
3
/**
4
+ * 循环引用的垃圾回收
5
+ *
4
6
* @author : chen weijie
5
7
* @Date: 2018-10-24 9:20 AM
6
8
*/
7
9
public class ForEachReferenceDemo {
10
+
11
+
12
+ public Object instance = null ;
13
+ private static final int _1MB = 1024 * 1024 ;
14
+
15
+ //这个成员变量的唯一作用就是站点内存,一边在GC日志中可以看清楚是否被回收过
16
+
17
+ private byte [] bigSize = new byte [2 * _1MB ];
18
+
19
+ public static void testGC () {
20
+
21
+ ForEachReferenceDemo objectA = new ForEachReferenceDemo ();
22
+ ForEachReferenceDemo objectB = new ForEachReferenceDemo ();
23
+ objectA .instance = objectA ;
24
+ objectB .instance = objectB ;
25
+ objectA = null ;
26
+ objectB = null ;
27
+ System .gc ();
28
+
29
+
30
+ }
31
+
32
+ public static void main (String [] args ) {
33
+ testGC ();
34
+ }
35
+
36
+
8
37
}
You can’t perform that action at this time.
0 commit comments