Skip to content

Instantly share code, notes, and snippets.

@sinewalker
Created January 21, 2017 11:18
Show Gist options
  • Select an option

  • Save sinewalker/84778fe3271a63a85c9cc386d7d48898 to your computer and use it in GitHub Desktop.

Select an option

Save sinewalker/84778fe3271a63a85c9cc386d7d48898 to your computer and use it in GitHub Desktop.
Java MaxMemory
// See my answer to Stack Overflow: Maximum java heap size of a 32-bit JVM on a 64-bit host
// http://stackoverflow.com/questions/1434779/maximum-java-heap-size-of-a-32-bit-jvm-on-a-64-bit-os/7019624#7019624
// and my blog: http://milosophical.me/blog/2007/03/04/32-bit-windows-and-jvm-virtual-memory-limit.html
public class MaxMemory {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
long totalMem = rt.totalMemory();
long maxMem = rt.maxMemory();
long freeMem = rt.freeMemory();
double megs = 1048576.0;
System.out.println ("Total Memory: " + totalMem + " (" + (totalMem/megs) + " MiB)");
System.out.println ("Max Memory: " + maxMem + " (" + (maxMem/megs) + " MiB)");
System.out.println ("Free Memory: " + freeMem + " (" + (freeMem/megs) + " MiB)");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment