java.io.ObjectOutputStream OutOfMemoryError Exception

Question 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!
Reply With Quote
  # 2   <script type="text/javascript"></script>  
Old February 13th, 2008, 04:07 PM
TheBerk TheBerk is offline <script type="text/javascript"></script>
Member
 
Join Date: Jan 2008
Posts: 27
TheBerk is an unknown quantity at this point (<10)
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."
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值