среда, 1 августа 2012 г.

memory: heap

    Выделяем 16G одной строчкой:
class Test {
    public static void main(String[] args) {
        long[] s = new long[Integer.MAX_VALUE];
    }
}

class Test {
    public static void main(String[] args) {
        while (true) {
            new Object();
        }
    }
}

class Test {
    public static void main(String[] args) {
        Object obj;
        while (true) {
            obj = new Object();
        }
    }
}

class Test {
    public static void main(String[] args) {
        List<Object> list = new ArrayList<>();
        while (true) {
            list.add(new Object());
        }
    }
}

class Test {
    public static void main(String[] args) {
        Object[] ref = new Object[1];
        while (true) {
            Object[] a = new Object[1];
            Object[] b = new Object[1];
            a[0] = b;
            b[0] = a;
            ref[0] = a;
        }
    }
}

class Test {
    public static void main(String[] args) {
        Object[] ref = new Object[1];
        while (true) {
            ref = new Object[]{ref};
        }
    }
}

class Test {
    public static void main(String[] args) {
        Object[] ref = new Object[1];
        while (true) {
            ref[0] = new Object[]{ref};
            ref = (Object[]) ref[0];
        }
    }
}