How to withdraw a bunch
4 answers
Easier than adding items to a list of arrays imho is just cut out the middleman:
public static void main(String[] args) {
int[] a = new int[Integer.MAX_VALUE];
}
Well theoretically not guaranteed to result in OoME, but since the arrealist uses an internal matrix, the same restrictions apply to other solutions as well.
+2
source to share
Create ArrayList
and add objects to it:
private static final List<String> list = new ArrayList<String>();
// ...
while(true) list.add("Hello World");
and, BTW, it's called a Memory Leak
. OutOfMemoryError
will be reset.
Also, if you want StackOverflow, you can do it with an infinite recursive method:
public void Foo(){Foo();}
StackOverflowError
will be reset.
0
source to share