[CSHARP-2159] Bson.IO.Bytebuffer never dispose Created: 28/Jan/18  Updated: 05/Apr/19  Resolved: 31/Aug/18

Status: Closed
Project: C# Driver
Component/s: API, BSON
Affects Version/s: 2.5
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: soheil karami Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Untitled.png    
Issue Links:
Related
related to CSHARP-1110 Make RawBsonDocument.dispose() an no-op Backlog

 Description   

I Have an application using mongodb,for data storage,
but when request in my application grow,application memory grow too,and when load going down memory not released , i going to check application with memory profiler application(ANTS
memory profiler) when check the result i saw Bson.IO.Bytebuffer instance get the all memory

iam using replica set with three server,.net application,and one static instance for mongo client
for all thread,

my connection settings in application

var mongoSetting = new MongoClientSettings()
{
MaxConnectionPoolSize = 7500,
Servers = mongoServerAddress,
ConnectionMode = ConnectionMode.ReplicaSet,
ReplicaSetName = "switch",
ClusterConfigurator = builder =>

{ builder.ConfigureCluster (settings => settings.With(serverSelectionTimeout: TimeSpan.FromSeconds(2))); }

,

};

the image attached is the result of ANTS application



 Comments   
Comment by Robert Stam [ 31/Jan/18 ]

Regarding RawBsonDocument and RawBsonArray, we believe it would be a common application error to forget to call Dispose on them, which would prevent the underlying byte buffer from being returned to the pool.

CSHARP-1110 proposes having RawBsonDocument and RawBsonArray make a copy of the bytes so that the application is no longer burdened with the responsibility of calling Dispose.

Comment by Robert Stam [ 31/Jan/18 ]

ByteBuffer instances are cached in a pool to be reused later, so it is normal for them not to be released.

This would only be a bug if you were seeing memory use going up forever.

Instances of RawBsonDocument and RawBsonArray also reference bytes in an underlying ByteBuffer and prevent them from being returned to the pool until the RawBsonDocument or RawBsonArray is disposed. It is possible that you are holding to RawBsonDocument or RawBsonArray instances in your application.

Can you confirm whether you are seeing runaway memory or use? Or are you simply observing the cached instances?

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