Why is OutOfMemoryError thrown after writing a large number of objects into an ObjectOutputStream?
When you write a large number of objects into an Object output stream, these objects might be unreachable by the reference that the reference table is hoding. If they are not garbage collected by the JVM, resulting the running out of memory error. A call to the ObjectOutputStream.reset() method resets the object/handle table to its initial state, allowing all previously written objects to be eligible for garbage collection.