0

Once this exception is thrown, is object that caused this thrown out of memory? Does it happen right away?

In other words, if i am adding objects to a list, at some point this can no longer happen and OOM error is thrown. At that time, does anything happen to the list itself?

java.lang.OutOfMemoryError: Java heap space
1
  • This is an Error (Unrecoverable). Commented Jul 6, 2012 at 2:21

3 Answers 3

1

This is thrown when a new object could not be created. The current object will continue to exist.

However, due to the nature of an error like this the current code will stop executing and it's likely that the current object will be garbage-collected soon. It just depends on the structure of your code and whether references are still being held to your object.

Sign up to request clarification or add additional context in comments.

Comments

0

From documentation:

Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

2 Comments

There is no guarantee that the JVM is actually able to reclaim the memory at all.
0

According to http://docs.oracle.com/javase/6/docs/api/, an OutOfMemoryError is:

Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

So it happens as soon as the JVM sees that it does not have enough heapspace to allocate memory for the new object you're trying to create. So the object never gets created because you don't have enough memory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.