title: MongoDB - Memory leak Issue in Java driver
body: <p>I am running a java project and use mongodb as the back end DB. Here I am getting the following warning everytime I run the web application</p>
  
  <pre><code>SEVERE: The web application [/Padua] appears to have started a thread named [MongoCleaner576026458]     but has failed to stop it. This is very likely to create a memory leak.
  Aug 29, 2014 11:41:14 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
  </code></pre>
  
  <p>I got to know that this error is because of mongoclient not closed properly. But I am making sure I am closing the connection in every instance </p>
  
  <p>The following is my coding</p>
  
  <pre><code>public class DBUtils {
  MongoClient mongoClient;
  DB db;
  DBCollection messages;
  DBCollection customerDetails;
  public MongoClient connectToDB(String dBName){
      try {
          mongoClient = new MongoClient("XX.YYY.ZZZ.AAA" , 27017 );
          db = mongoClient.getDB(dBName);
          db.createCollection("A", null);
          db.createCollection("B", null);         
          db.createCollection("C", null); 
          BasicDBObject msgindexobj = new BasicDBObject();
          msgindexobj.put("processedword", 1);
          msgindexobj.put("mobileID", 1);
          db.getCollection("Messages").ensureIndex(new BasicDBObject("location", "2dsphere"), "geospatial");
      } catch (UnknownHostException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return mongoClient;
  }
  
  
  public void disConnectFromDB(MongoClient mongoclient){
      if (mongoclient!=null){
          mongoclient.close();
          mongoclient=null;
      }       
  }
  }
  </code></pre>
  
  <p>And I am calling this type of code to access DB</p>
  
  <pre><code>DBUtils dbUtils=new DBUtils();
        mongoclient= dbUtils.connectToDB("pingpong");
        DB db = mongoclient.getDB("pingpong");
  dbUtils.disConnectFromDB(mongoclient);  
  </code></pre>
  
  <p>Am I doing something wrong here....Please help me in resolving this issue. Thanks for your time.</p>