mirror of
https://github.com/corda/corda.git
synced 2025-01-27 06:39:38 +00:00
9bb3d6b972
git-subtree-dir: sgx-jvm/avian git-subtree-mainline: f978eab8d134c88f88ff67e49458a771c32351db git-subtree-split: 09e4fe60d01f4f4bfb6b2976973bb4913ef61edc
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();
|
|
}
|
|
}
|
|
}
|