[Solved] best Java code to control big heap memeory used (like 1G) [closed]
Quickly allocate 1 GB of memory: byte[][] memoryWaster = new byte[1024][1_048_576]; See last test run below for successful allocation of 16 GB of memory. Test program Runtime runtime = Runtime.getRuntime(); System.out.printf(“total: %11d max: %d%n”, runtime.totalMemory(), runtime.maxMemory()); System.out.printf(“used: %11d%n”, runtime.totalMemory() – runtime.freeMemory()); System.gc(); System.out.printf(“gc: %11d%n”, runtime.totalMemory() – runtime.freeMemory()); byte[][] memoryWaster = new byte[1024][1_048_576]; memoryWaster[0][0] = 2; … Read more