I have this strange issue going on in my one of production application. I have checked the heap space on the server and do not found any anomalies (Please see below screen) but still i am getting the error below on few operations that my application does. Is it possible?
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1876)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1785)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1188)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:347)
I am suspecting the issue to be one of the list in the code that will be filled up by almost 2M records at once, but still not sure why this is happening as the heap is not showing full or used at maximum, but still getting this error. Is it possible? what are the scenarios possible, is there a way to prevent this. This is production application so i would not be able to share the code. Please help me out.
It doesn't have to be full to throw OutOfMemoryError
. It has to be in a condition where the current size plus the size of the next requested allocation exceeds the maximum. Here you are clearly copying a large enough array that allocating it would trip (has tripped) this condition.