4

我探索netty在 VM 之间通信对象。我分别使用ObjectEncoder&ObjectDecoder来序列化这些。

我很快发现这个解决方案仅限于最大 1MB 大小的对象。由于我打算传达更大的对象并且考虑到我不打算限制这个大小,我曾经Integer.MAX_VALUE设置最大帧长度。

不幸的是,看起来这个值被用来初始化一些缓冲区,从而导致不必要的 GC-ing 并且很可能在 OutOfMemory 中。

有没有办法在使用 DynamicChannelBuffers 时创建无限的 ObjectEncoder/Decoder,以免浪费太多内存?

4

1 回答 1

4

ObjectDecoder extends LengthFieldBasedFrameDecoder which extends FrameDecoder. FrameDecoder manages the decode buffer and it uses a dynamic buffer with initial capacity of 256.

However, once you receive a large object, the dynamic buffer expands itself, but never shrinks. If you have multiple connections that exchange large objects, your ObjectDecoder will all have a very large buffer eventually, potentially leading to OutOfMemoryError.

This issue has been fixed last week and a new release (3.2.7.Final) will be released this week.

于 2011-11-09T18:55:03.187 回答