mirror of
https://github.com/corda/corda.git
synced 2024-12-29 09:18:58 +00:00
9bb3d6b972
git-subtree-dir: sgx-jvm/avian git-subtree-mainline:f978eab8d1
git-subtree-split:09e4fe60d0
63 lines
1.2 KiB
Java
63 lines
1.2 KiB
Java
public class OutOfMemory {
|
|
// assume a 128MB heap size:
|
|
private static final int Padding = 120 * 1024 * 1024;
|
|
|
|
private static class Node {
|
|
Object value;
|
|
Node next;
|
|
}
|
|
|
|
private static void bigObjects() {
|
|
Object[] root = null;
|
|
while (true) {
|
|
Object[] x = new Object[1024 * 1024];
|
|
x[0] = root;
|
|
root = x;
|
|
}
|
|
}
|
|
|
|
private static void littleObjects() {
|
|
byte[] padding = new byte[Padding];
|
|
Node root = null;
|
|
while (true) {
|
|
Node x = new Node();
|
|
x.next = root;
|
|
root = x;
|
|
}
|
|
}
|
|
|
|
private static void bigAndLittleObjects() {
|
|
byte[] padding = new byte[Padding];
|
|
Node root = null;
|
|
while (true) {
|
|
Node x = new Node();
|
|
x.value = new Object[1024 * 1024];
|
|
x.next = root;
|
|
root = x;
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
bigObjects();
|
|
throw new RuntimeException();
|
|
} catch (OutOfMemoryError e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
try {
|
|
littleObjects();
|
|
throw new RuntimeException();
|
|
} catch (OutOfMemoryError e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
try {
|
|
bigAndLittleObjects();
|
|
throw new RuntimeException();
|
|
} catch (OutOfMemoryError e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|