The standard compiler is not so smart.
class A
{
private Object[] array;
public A()
{
array = new Object[10000000];
}
}
public static void main(String[] args)
{
LinkedList<A> list = new LinkedList<A>();
while (true)
{
list.add(new A());
}
}
This code throws an exception after a very small number of loops, so there is definitely no answer to the original question.
source
share