Re: Out of memory with file streams
- From: Zig <none@xxxxxxxxxxx>
- Date: Mon, 17 Mar 2008 17:29:01 -0400
On Mon, 17 Mar 2008 15:13:44 -0400, Mark Space <markspace@xxxxxxxxxxxxxx> wrote:
Hendrik Maryns wrote:The API could have been more informing over the memory implications of this backreferencing mechanism. The memory footprint is not even mentioned in the Javadoc of the reset() method.
"Reset" is also a terrible name for a method of an output stream. "Reset" normally means something totally different when talking about IO streams.
From collections, "clear" probably would have been better. Maybe "cleanUpMemory" would have been even better. And maybe using weak references would have been even better still. Don't make the user deal with the internal memory of an object.
Well, "reset" does reset the ObjectOutputStream back to the state it was initialized to: all objects are new, no class descriptors have been written, etc. Using reset() will decrease your memory overhead, but at the cost of increasing your data size (since the class descriptors have to be re-serialized).
Weak / Soft references would be slick, but there is an extra "quirk" that would have to be addressed. reset() will put a RESET marker in the stream in order for ObjectInputStream to recognize that the stream has been reset (at which point it will dump it's references). Even while ObjectOutputStream could use soft references to determine that an object is no longer referenced, you also have to notify ObjectInputStream whent it's safe to clear it's references to objects that will not be subsequently re-referenced later in the stream.
For simple objects you can get around all of this by using
ObjectOutputStream.writeUnshared() / ObjectInputStream.readUnshared(), but those will still graph references for the nested object you'll get in a tree structure :/
Anyway, hope that was interesting food for thought,
-Zig
.
- References:
- Out of memory with file streams
- From: Hendrik Maryns
- Re: Out of memory with file streams
- From: Zig
- Re: Out of memory with file streams
- From: Hendrik Maryns
- Re: Out of memory with file streams
- From: Mark Space
- Out of memory with file streams
- Prev by Date: Re: Java UI Hanging with wait()
- Next by Date: Re: Out of memory with file streams
- Previous by thread: Re: Out of memory with file streams
- Next by thread: Re: Out of memory with file streams
- Index(es):
Relevant Pages
|