Java OutOfMemoryError strange behaviour
Posted
by
Evgeniy Dorofeev
on Stack Overflow
See other posts from Stack Overflow
or by Evgeniy Dorofeev
Published on 2012-11-23T14:24:17Z
Indexed on
2012/11/23
17:05 UTC
Read the original article
Hit count: 396
java
|outofmemoryerror
Assuming we have a max memory of 256M, why does this code work:
public static void main(String... args) {
for (int i = 0; i < 2; i++)
{
byte[] a1 = new byte[150000000];
}
byte[] a2 = new byte[150000000];
}
but this one throw an OOME?
public static void main(String... args) {
//for (int i = 0; i < 2; i++)
{
byte[] a1 = new byte[150000000];
}
byte[] a2 = new byte[150000000];
}
© Stack Overflow or respective owner