On 07/12/2017 00:19, James Roper wrote:
:

One issue that I'm not sure about is the consequences of using direct buffers with regards to garbage collection. If direct buffers are never copied onto the heap, and are never reused, lets say you're just implementing a proxy passing buffers through from one connection to another, then the heap usage of the application may be very small, and this could mean that garbage collection is done very infrequently. As I understand it, this can result in direct buffers staying around for a long time, and possibly causing the system to run out of memory. Does anyone have any experience with that, and how to deal with it? We don't generally have this problem in Akka because we always copy our buffers onto the heap into an immutable structure, so even if we do use direct buffers and don't reuse them, our heap usage grows at least as fast as our direct buffer usage grows, which means total memory usage won't exceed twice the size of the heap since eventually garbage collection will clean both up.
This thread is getting a little off-topic but just to say that you can limit the amount of memory reserved for direct buffers. Attempts to allocate further direct buffers will trigger GC and reference processing. Yes, this can be expensive. This area improved significantly in JDK 9 so that the retry coordinates with the reference processing and mostly avoids spurious OOME that were possible with older releases.

-Alan

Reply via email to