Created
April 24, 2018 11:58
-
-
Save morris821028/235d9fa59f5fce4c4767e2b3c4075bc8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package bsh; | |
import org.junit.Test; | |
public class MemoryTest { | |
static public double printUsage() { | |
double cap = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); | |
cap /= 1048576; | |
System.out.printf("Usage %f MB\n", cap); | |
return cap; | |
} | |
static public void blockAlloc(int v) { | |
byte t[] = new byte[v]; | |
System.out.printf("Alloc %d\n", t.length); | |
} | |
@Test | |
public void memory_gc() { | |
printUsage(); | |
int v = 1024 * 1048576; | |
{ | |
// Case 1: | |
// byte t[] = new byte[v]; | |
// System.out.printf("Alloc %d\n", t.length); | |
// Case 2: | |
blockAlloc(v); | |
} | |
printUsage(); | |
System.gc(); | |
printUsage(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment