java.io.ObjectOutputStream OutOfMemoryError Exception
Hi, I haven't touched Java in a good year, and even then I was just a beginner.
I'm doing some research to see if there is a limit on the amount of data which can be output from java.io.ObjectOutputStream (I was told 4GB). I just have a simple program which continually loops and outputs objects via java.io.ObjectOutputStream to a file. However, at about 34.9MB of data outputted, I recieve this exception:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.io.ObjectOutputStream$HandleTable.growSpine(Unknown Source)
at java.io.ObjectOutputStream$HandleTable.assign(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at MainTest.main(MainTest.java:31)
I've adjusted the max heap size to Xmx1024m (it looks like that is as high as it will go).
I was wondering if there was a way to clear out the heap for java.io.ObjectOutputStream while using it, so I can output much more data.
Thanks!
I'm doing some research to see if there is a limit on the amount of data which can be output from java.io.ObjectOutputStream (I was told 4GB). I just have a simple program which continually loops and outputs objects via java.io.ObjectOutputStream to a file. However, at about 34.9MB of data outputted, I recieve this exception:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.io.ObjectOutputStream$HandleTable.growSpine(Unknown Source)
at java.io.ObjectOutputStream$HandleTable.assign(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at MainTest.main(MainTest.java:31)
I've adjusted the max heap size to Xmx1024m (it looks like that is as high as it will go).
I was wondering if there was a way to clear out the heap for java.io.ObjectOutputStream while using it, so I can output much more data.
Thanks!
#
2
<script type="text/javascript"></script>
| |||
| |||
Re: java.io.ObjectOutputStream OutOfMemoryError Exception
Looks like I found an answer if anyone else has this problem. Using the ObjectOutputStream.reset() function every so often clears it up. Here is why:
"Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream? The ObjectOutputStream maintains a table mapping objects written into the stream to a handle. The first time an object is written to a stream, its contents are written into the stream; subsequent writes of the object result in a handle to the object being written into the stream. This table maintains references to objects that might otherwise be unreachable by an application, thus, resulting in an unexpected situation of running out of memory. A call to the ObjectOutputStream.reset() method resets the object/handle table to its initial state, allowing all previously written objects to be elgible for garbage collection. See handle." |