注意:不可以使用debug模式,可以使用代码现场睡眠模式测试,启动main方法后,在本地进程选择相应的执行类
public class Main2 {
@SneakyThrows
public static void main(String[] args) {
if (true) {
Thread.sleep(5000);
byte[] placeHolder = new byte[64 * 1024 * 1024];
System.out.println(placeHolder.length / 1024);
Thread.sleep(5000);
}
System.gc();
Thread.sleep(2000);
}
}
public class Main2 {
@SneakyThrows
public static void main(String[] args) {
if (true) {
Thread.sleep(5000);
byte[] placeHolder = new byte[64 * 1024 * 1024];
System.out.println(placeHolder.length / 1024);
Thread.sleep(5000);
placeHolder=null;
}
System.gc();
Thread.sleep(2000);
}
package org.jeecg.modules.system.service.impl;
import lombok.SneakyThrows;
/**
* @Author xu
* @create 2023/7/13 01
*/
public class Main2 {
@SneakyThrows
public static void main(String[] args) {
if (true) {
Thread.sleep(5000);
byte[] placeHolder = new byte[64 * 1024 * 1024];
System.out.println(placeHolder.length / 1024);
Thread.sleep(5000);
placeHolder=null;
}
System.gc();
Thread.sleep(2000);
}
}
G:\hdxProject\java\org\jeecg\modules\system\service\impl>javac Main2.java
G:\hdxProject\java>
G:\hdxProject\java>java org/jeecg/modules/system/service/impl/Main2
65536
G:\hdxProject\java>
G:\hdxProject\java>java -XX:+PrintGC org/jeecg/modules/system/service/impl/Main2
65536
[GC (System.gc()) 69447K->66392K(373248K), 0.0203310 secs]
[Full GC (System.gc()) 66392K->66202K(373248K), 0.0147270 secs]
G:\hdxProject\java>
G:\hdxProject\java>java -XX:+PrintGCDetails org/jeecg/modules/system/service/impl/Main2
65536
[GC (System.gc()) [PSYoungGen: 69447K->784K(113664K)] 69447K->66328K(373248K), 0.0200134 secs] [Times: user=0.00 sys=0.02, real=0.02 secs]
[Full GC (System.gc()) [PSYoungGen: 784K->0K(113664K)] [ParOldGen: 65544K->66202K(259584K)] 66328K->66202K(373248K), [Metaspace: 2735K->2735K(1056768K)], 0.0047035 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
PSYoungGen total 113664K, used 978K [0x0000000741980000, 0x0000000749800000, 0x00000007c0000000)
eden space 97792K, 1% used [0x0000000741980000,0x0000000741a74920,0x0000000747900000)
from space 15872K, 0% used [0x0000000747900000,0x0000000747900000,0x0000000748880000)
to space 15872K, 0% used [0x0000000748880000,0x0000000748880000,0x0000000749800000)
ParOldGen total 259584K, used 66202K [0x0000000644c00000, 0x0000000654980000, 0x0000000741980000)
object space 259584K, 25% used [0x0000000644c00000,0x0000000648ca6970,0x0000000654980000)
Metaspace used 2741K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 305K, capacity 386K, committed 512K, reserved 1048576K
G:\hdxProject\java>