title: MongoDB / C# Driver and Memory Issue
body: <p>I'm using MongoDB 1.8.2 (Debian) and mongo-csharp-driver 1.1.0.4184 (IIS 7.5/.Net 4.0 x64).</p>
  
  <p>Multiple items are inserted every second in a existing collection with ~ 3,000,000 objects (~ 1.9 GB).<br>
  The WebServer memory is increasing by ~ 1 MB after every insert -> which leads very fast to > 2 GB memory usage.<br>
  The memory is never released anymore and only an application pool recycle can free the memory.</p>
  
  <p>Any ideas? </p>
  
  <pre><code>MongoServer server = MongoServer.Create(mongoDBConnectionString);
  MongoDatabase database = server.GetDatabase(dbName);                
  
  MongoCollection&lt;Result&gt; resultCollection = database.GetCollection&lt;Result&gt;("Result");
  resultCollection.Insert(result);
  </code></pre>
  
  <p>result looks like</p>
  
  <pre><code>private class Result
  {
      public ObjectId _id { get; set; }            
      public DateTime Timestamp { get; set; }
      public int Location { get; set; }            
      public string Content { get; set; }
  }
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>My problem is not the insert, it's the select - sorry weird codebase to investigate ;-)</p>
  
  <p>I reproduced it with this sample Code:</p>
  
  <pre><code>Console.WriteLine("Start - " + GC.GetTotalMemory(false).ToString("#,###,##0") + " Bytes");
  
  for (int i = 0; i &lt; 10; i++)
  {
      MongoServer server = MongoServer.Create(mongoDBConnectionString);
      MongoDatabase database = server.GetDatabase(dbName);
  
      MongoCollection&lt;Result&gt; resultCollection = database.GetCollection&lt;Result&gt;("Result");
      var query = Query.And ( Query.EQ("Location", 1), Query.GTE("Timestamp", DateTime.Now.AddDays(-90)) );
  
      MongoCursor&lt;Result&gt; cursor = resultCollection.FindAs&lt;Result&gt;(query);
  
      foreach (Result result in cursor)
      {
          // NOOP
      }
  
      Console.WriteLine(i + " - " + GC.GetTotalMemory(false).ToString("#,###,##0") + " Bytes");
  }
  </code></pre>
  
  <p>Output from a .Net 4.0 <strong>Console Application</strong> with 10.000 results in the cursor:</p>
  
  <pre><code>Start - 193.060 Bytes
  0 - 12.736.588 Bytes
  1 - 24.331.600 Bytes
  2 - 16.180.484 Bytes
  3 - 13.223.036 Bytes
  4 - 30.974.892 Bytes
  5 - 13.335.236 Bytes
  6 - 13.439.448 Bytes
  7 - 13.942.436 Bytes
  8 - 14.026.108 Bytes
  9 - 14.113.352 Bytes
  </code></pre>
  
  <p>Output from a .Net 4.0 <strong>Web Application</strong> with the same 10.000 results in the cursor:</p>
  
  <pre><code>Start - 5.258.376 Bytes 
  0 - 20.677.816 Bytes
  1 - 29.893.880 Bytes
  2 - 43.783.016 Bytes
  3 - 20.921.280 Bytes
  4 - 34.814.088 Bytes
  5 - 48.698.704 Bytes
  6 - 62.576.480 Bytes
  7 - 76.453.728 Bytes
  8 - 90.347.360 Bytes
  9 - 104.232.800 Bytes
  </code></pre>
  
  <p><strong>RESULT:</strong></p>
  
  <p>Bug was reported to 10gen and they will fix it in <strong><em>version >= 1.4</em></strong> (they are working currently on 1.2)!!!</p>