title: Hazelcast OFFHEAP Map Taking Up Space in Heap
body: <p>I need Hazelcast to store a relatively large size of data (16GB x 3 nodes). I carried out a few tests within JVM heap memory and was more than satisfied with the results.</p>
  
  <p>However, when I set the map to be stored in off-heap memory; I don't see any changes in memory usage. Shouldn't I see lower heap memory values when I use off-heap than in default BINARY in-memory-format? (I'm using a trial license and hazelcast-3.2-RC-ee JAR)</p>
  
  <p>Here's the configuration file part:</p>
  
  <pre><code>&lt;map name="data"&gt;
      &lt;in-memory-format&gt;OFFHEAP&lt;/in-memory-format&gt;
      &lt;backup-count&gt;0&lt;/backup-count&gt;
      &lt;async-backup-count&gt;0&lt;/async-backup-count&gt;
      &lt;statistics-enabled&gt;false&lt;/statistics-enabled&gt;
  &lt;/map&gt;
  &lt;map name="default"&gt;
      &lt;in-memory-format&gt;OFFHEAP&lt;/in-memory-format&gt;
      &lt;backup-count&gt;1&lt;/backup-count&gt;
      &lt;async-backup-count&gt;0&lt;/async-backup-count&gt;
      &lt;time-to-live-seconds&gt;0&lt;/time-to-live-seconds&gt;
      &lt;max-idle-seconds&gt;0&lt;/max-idle-seconds&gt;
      &lt;eviction-policy&gt;NONE&lt;/eviction-policy&gt;
      &lt;max-size policy="PER_NODE"&gt;0&lt;/max-size&gt;
      &lt;eviction-percentage&gt;25&lt;/eviction-percentage&gt;
      &lt;merge-policy&gt;com.hazelcast.map.merge.PassThroughMergePolicy&lt;/merge-policy&gt;
  
  &lt;/map&gt;
  </code></pre>
  
  <p>And this is the related code :</p>
  
  <pre><code>    String instanceName = wrapper.getHazelcastInstance().getName();
      int port = wrapper.getHazelcastInstance().getCluster().getLocalMember().getInetSocketAddress().getPort();
      logger.info("Hazelcast instance " + instanceName + " is running at port " + port);
  
      while (true) {
          System.out.print("Enter number of data to insert :");
          String s = null;
          while (s == null) {
              s = System.console().readLine();
          }
          Long dataCount = null;
          try {
              dataCount = Long.valueOf(s.trim());
          } catch (NumberFormatException e) {
              System.out.println("That won't do :)");
              continue;
          }
  
          if (dataCount &lt; 0) {
              break;
          }
  
          int dataSize = wrapper.getHazelcastInstance().getMap("data").entrySet().size();
          try {
              for (long l = dataSize; l &lt; dataSize + dataCount; l++) {
                  RoundRobinConsolidatedUtilizationData datum = createData();
                  wrapper.getHazelcastInstance().getMap("data").put(l, datum);
              }
          } catch (Exception e) {
              logger.severe("Exception occurred : " + e.getMessage());
          } catch (Throwable throwable) {
              logger.severe("Error occurred; terminating instance : " + throwable.getMessage());
              break;
          }
  
          logger.info("Total data count in cluster: " + wrapper.getHazelcastInstance().getMap("data").entrySet().size());
      }
  </code></pre>
  
  <p>Finally, here's the command-line that I use when running my HazelcastWrapper class</p>
  
  <pre><code>java -XX:MaxDirectMemorySize=512M -Dhazelcast.elastic.memory.enabled=true -Dhazelcast.elastic.memory.total.size=500M -Dhazelcast.elastic.memory.chunk.size=12K -cp hazelcast-3.2-RC-ee.jar:hazelcast-app-1.0-SNAPSHOT.jar:sm-datacache-api-1.0.jar tr.com.kron.hazelcast.HazelcastWrapper
  </code></pre>
  
  <p>Actually, I tried various <code>-D</code> and <code>-XX:MaxDirectMemorySize</code> values. They all ended up the same.</p>
  
  <p>I'm adding 3000 records at a time to the cluster (this last test included a solo node); when I add 4th 3000 records, the VM throws <code>java.lang.OutOfMemoryError: Java heap space</code> error. If the map was really off-heap; I shouldn't be getting a heap space error.</p>
  
  <p>Below is the jConsole capture of heap memory usage. The rises seen are the times I added 3K map data. The last fall of memory is when I get the OutOfMemoryError.
  <img src="https://i.stack.imgur.com/LxuVV.png" alt="Heap memory usage"></p>
  
  <p>What could I be missing?</p>
  
  <p>Thanks in advance, (even for just reading this long anyway :))</p>