ObjectOutputStream oout = this.oout;
if (resetInterval != 0) {
// Resetting will prevent OOM on the receiving side.
writtenObjects ++;
if (writtenObjects % resetInterval == 0) {
oout.reset();
// Also discard the byproduct to avoid OOM on the sending side.
buffer.discardReadBytes();
}
}