-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Java Drivers
-
None
-
None
-
None
-
None
-
None
-
None
CommandCursorResult holds the batch in its results field. Those same results are also referenced via nextBatch. When next() or tryNext() is called, the referenced results are returned to the caller and nextBatch field is nullified. However, if the cursor then sits idle for a long time and the batch was large, the entries are still retained via CommandCursorResult.results, causing unnecessary heap usage. Because a server batch is capped at ~16 MiB (16 mebibytes), retaining CommandCursorResult.results can keep up to ~16 MiB per open cursor in heap.
This happens because we still need CommandCursorResult for metadata (resume tokens, server cursor, etc.), but the batch itself is no longer needed after next()/tryNext() returns. We should clear the reference to the consumed results in CommandCursorResult so they can be garbage-collected, while preserving required metadata.
Acceptance criteria:
- After a batch is delivered by next()/tryNext(), clear (null or empty) CommandCursorResult.results once nextBatch is consumed, without affecting resume tokens/server cursor state.