title: Java's RAM usage doesn't correspond to what the Task Manager says
body: <p>I have been playing with Java's JVM by making a <code>1024^3</code> (basically 1Gb) length byte array. I measured the RAM usage before, after the array creation and after the array's destruction by the garbage collector, using both the Task Manager (looking at the process) and this little snippet:</p>
  
  <pre><code>public static void showMemory() {
      System.out.println("Memory used: "
              + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024.D * 1024.D) + "mB.");
  }
  </code></pre>
  
  <p>The aforementioned code shows 2Mb, 1029Mb and 2Mb, respectively. -> It all seems normal.
  However, when looking at the TaskManager, the RAM usage by Java is 2mb at first, then goes to 1052Mb and stays there, even if the snippet shows 2Mb.</p>
  
  <p>As I would like to have Java use the least resource, how can I solve this problem?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I have done some research and have figured out the terms to use. In fact, the <strong>native</strong> memory's does not resemble the <strong>heap</strong> memory's value, and is often greater than the heap memory. Is there a way to reduce the native memory used, so that it is close to the heap memory?</p>