title: Java garbage collection problem
body: <p>So I have this extremely memory-intensive Java application I'm building, which builds a tree of millions of nodes. Using the handy dandy Runtime methods for getting heap information, I built a nice little method that displays the current memory usage, as shown below:</p>
  
  <pre><code>public void displayMemoryUsage() {
      long maxMem = Runtime.getRuntime().maxMemory();
      long freeMem = Runtime.getRuntime().freeMemory();
      long heapMem = Runtime.getRuntime().totalMemory();
      long usedMem = heapMem - freeMem;
      System.out.println("Memory used: " + (int) (usedMem * 100 / maxMem) + "%");
  }
  </code></pre>
  
  <p>So just to test it out, I had the tree expand its root node (into 2128 children), and then expanded each one of those children (for a total of approx. 4 million nodes in the tree). The memory displays 11% used. I then set the root of the tree to be one of the root's children, and in doing so remove all references to the root's other children. Theoretically, this should remove 2127/2128 of the original root's children. I ran Java's Runtime.getRuntime().gc() method for forced garbage collection, and told it to display the memory usage again. This time, I got 10%. In theory, should this new percentage not be more like 0.05%, or 1/2128th of the value before setting the new root?</p>
  
  <p>Any thoughts why it's not picking up the garbage properly?</p>