We have a webAPI in our project which is very simple but it does not release the memory after execution and every time it is executed, it increases the used memory.
I was using webAPI 2.0 and MongoDB as back end server.
public class LogsController:ApiController
{
BsonDocument __docs;
IMongoDatabase __db;
IMongoCollection<BsonDocument> __docsColl;
[Route("api/Logs")]
public async Task<int> Post(RequestData logs)
{
if (logs.Token == "I")
{
__db = new MongoClient(new MongoClientSettings
{
Server = new MongoServerAddress("serverIP", 27017),
Credentials = new[] { MongoCredential.CreateCredential("database", "user name", "password") }
}).GetDatabase("connect_database");
__docs = new BsonDocument()
{
{ "Customer",logs.Customer}
};
__docsColl = __db.GetCollection<BsonDocument>("InsertData");
await __docsColl.InsertOneAsync(__docs);
}
logs = null;
return 1;
}
protected override void Dispose(bool disposing)
{
__docs = null;
__db = null;
__docsColl = null;
GC.SuppressFinalize(true);
base.Dispose(disposing);
}
}
I have tried all possible solutions I found, but so far no luck.