Skip to content

Latest commit

 

History

History
19 lines (19 loc) · 473 Bytes

File metadata and controls

19 lines (19 loc) · 473 Bytes

Java Heap Space Out of Memory Exception

class Main {
    public static void main(String[] args) {
        int len = 0, oldlen = 0;
        Object[] a = new Object[0];
        try {
            for (;;) {
                ++len;
                Object[] temp = new Object[oldlen = len];
                temp[0] = a;
                a = temp;
            }
        } catch (Error e) {
            System.out.println(e + ", " + (oldlen==len));
        }
    }
}