Enhance buffer handling to reduce direct list access. by vbabanin · Pull Request #1675 · mongodb/mongo-java-driver

LGTM shouldn't we release the cached buffer when calling close? (the underlying Native C/C++ buffer could be reference counted and needs to drop to 0 to actually free the memory)

In this case, currentByteBuffer is already part of bufferList, and we don’t retain any additional reference once it's cached, so it should be released as expected a part of bufferList traversal.

That said, this is a good point. It made me realize it would be clearer to explicitly nullify the currentByteBuffer field in close(), just as we already call bufferList.clear(). I’ll update accordingly - thanks! Let me know what you think.