There is a code for the calculator program, you need to find out how much memory it uses at startup. I saw this answer:

long usedBytes = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); 

But what it is and where it is, I can not imagine.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

If at startup, then you can compare the memory difference like this:

 public class Calculator { public static long mem() { Runtime runtime = Runtime.getRuntime(); return runtime.totalMemory() - runtime.freeMemory(); } public static void main(String[] args) { long before = mem(); // какие-то действия long after = mem(); System.out.println("Diff " + (after - before)); } }