public static void main(String[] args) { //获取当前堆的大小 byte 单位 long heapSize = Runtime.getRuntime().totalMemory(); System.out.println(heapSize); //获取堆的最大大小byte单位 //超过将抛出 OutOfMemoryException long heapMaxSize = Runtime.getRuntime().maxMemory(); System.out.println(heapMaxSize); //获取当前空闲的内存容量byte单位 long heapFreeSize = Runtime.getRuntime().freeMemory(); System.out.println(heapFreeSize); }
Java-获取堆的大小
最新推荐文章于 2022-08-03 08:30:00 发布