Make RawBsonDocument.dispose() an no-op

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • 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.

            Assignee:
            Unassigned
            Reporter:
            Robert Stam
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: