-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: BSON
-
None
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.
- is related to
-
CSHARP-2159 Bson.IO.Bytebuffer never dispose
-
- Closed
-