title: Play Framework 1.2.5 : OutOfMemoryError occured : Java heap space in play framework
body: <p>I gett <code>OutOfMemoryError</code> while querying MongoDb with the 400k records.
  I have a User collection with around 400k records. When I try to retrieve all the users (to dump it in elastic search), I get the  <code>OutOfMemoryError</code> error.</p>
  
  <p>I have gone through <a href="https://stackoverflow.com/questions/7331798/outofmemoryerror-occured-java-heap-space-in-play-framework">this</a> link and added <em>jvm.memory=-Xms64m -Xmx1024m</em> in the application.config, but still the same exception. </p>
  
  <p>Here is my stack trace - </p>
  
  <pre><code>OutOfMemoryError occured : Java heap space
  
  play.exceptions.JavaExecutionException: Java heap space
          at play.mvc.ActionInvoker.invoke(ActionInvoker.java:237)
          at Invocation.HTTP Request(Play!)
  Caused by: java.lang.OutOfMemoryError: Java heap space
          at java.util.HashMap.&lt;init&gt;(HashMap.java:209)
          at java.util.LinkedHashMap.&lt;init&gt;(LinkedHashMap.java:181)
          at org.bson.BasicBSONObject.&lt;init&gt;(BasicBSONObject.java:45)
          at com.mongodb.BasicDBObject.&lt;init&gt;(BasicDBObject.java:42)
          at com.mongodb.DefaultDBCallback._create(DefaultDBCallback.java:124)
          at com.mongodb.DefaultDBCallback.create(DefaultDBCallback.java:87)
          at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:68)
          at com.mongodb.DefaultDBCallback.objectStart(DefaultDBCallback.java:63)
          at org.bson.BasicBSONCallback.objectStart(BasicBSONCallback.java:63)
          at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:206)
          at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:197)
          at org.bson.BasicBSONDecoder.decodeElement(BasicBSONDecoder.java:207)
          at org.bson.BasicBSONDecoder._decode(BasicBSONDecoder.java:80)
          at org.bson.BasicBSONDecoder.decode(BasicBSONDecoder.java:58)
          at com.mongodb.DefaultDBDecoder.decode(DefaultDBDecoder.java:56)
          at com.mongodb.Response.&lt;init&gt;(Response.java:66)
          at com.mongodb.DBPort.go(DBPort.java:128)
          at com.mongodb.DBPort.call(DBPort.java:79)
          at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)
          at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:189)
          at com.mongodb.DBApiLayer$Result._advance(DBApiLayer.java:452)
          at com.mongodb.DBApiLayer$Result.hasNext(DBApiLayer.java:418)
          at com.mongodb.DBCursor._hasNext(DBCursor.java:503)
          at com.mongodb.DBCursor.hasNext(DBCursor.java:523)
          at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1520)
          at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1332)
          at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1318)
          at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:504)
          at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:499)
          at com.salambc.service.ProfileService.getUsers(ProfileService.java:895)
          at controllers.Admin.index(Admin.java:56)
  </code></pre>