[CSHARP-1110] Make RawBsonDocument.dispose() an no-op Created: 20/Nov/14  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-2159 Bson.IO.Bytebuffer never dispose Closed

 Description   

RawBsonDocument currently refers to the raw bytes using a reference counted reference directly into the underlying I/O buffers.

This is good for avoiding copying the bytes, but dangerous for correct memory management. RawBsonDocument is IDisposable for this reason, but any failure to call Dispose results in the underlying I/O buffer not being properly returned to the pool. Also, any remaining reference to even a single raw document (in a buffer that may contain many documents) is enough to prevent the entire buffer from being returned to the pool.

Perhaps it would be better to go ahead and copy the bytes out of the I/O buffers at the time the RawBsonDocument is created, thus allowing the I/O buffer to be returned to the pool much sooner (and preventing the scenario where failure to call Dispose prevents the buffer from being returned at all).

While this would involve one additional copy of the bytes, the cost would still be insignificant compared to deserialization into a regular BsonDocument.

The same would apply to RawBsonArray, LazyBsonDocument and LazyBsonArray.


Generated at Wed Feb 07 21:38:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.