Created
October 29, 2019 20:56
-
-
Save GotoFinal/c0a4d0c7cfb335ea9401848a6470e816 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestGC { | |
private static Runtime rt = Runtime.getRuntime(); | |
private static long free() { return rt.maxMemory() - rt.totalMemory() + rt.freeMemory(); } | |
public static void main(String[] args) throws InterruptedException, IOException { | |
int blocks = 50; | |
int typeSize = 8; | |
long initiallyFree = free(); | |
System.out.println("initially free: " + initiallyFree / 1000000); | |
ArrayList data = new ArrayList(); | |
for (int n = 0; n < blocks; n++) { | |
data.add(new long[1024 * 1024-2]); | |
} | |
System.gc(); | |
Thread.sleep(500); | |
long remainingFree = free(); | |
System.out.println("remaining free: " + remainingFree / 1000000); | |
System.out.println("used: " + (initiallyFree - remainingFree) / 1000000); | |
System.out.println("expected usage: " + blocks * typeSize); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment