Skip to content

Instantly share code, notes, and snippets.

@h-chal
Created November 7, 2022 20:31
Show Gist options
  • Select an option

  • Save h-chal/6fdefe86f81ab5ea5bcabb8687db542b to your computer and use it in GitHub Desktop.

Select an option

Save h-chal/6fdefe86f81ab5ea5bcabb8687db542b to your computer and use it in GitHub Desktop.
A method to measure the used memory (in bytes)
public static void recurse(int n) {
if (n == 1) {
long totalMem = Runtime.getRuntime().totalMemory();
long freeMem = Runtime.getRuntime().freeMemory();
long usedMem = totalMem - freeMem;
System.out.println(usedMem);
} else {
recurse(n-1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment