max heap size:
Runtime.getRuntime().maxMemory();
Some other calculations which you may find interesting:
Runtime runtime = Runtime.getRuntime();
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
long totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
long usedMemory = maxMemory - totalFreeMemory;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…