title: How to Clean up This Java Example Memory
body: <p>I was reading about garbage collection and finalization in Java and when I tried an example. I click button 1, and memory jumps up. But when I click button 2, the memory didn't free up used space!
  What did I do wrong and how do I free memory from unused objects?</p>
  
  <p>As far as I know (I may be wrong):</p>
  
  <ol>
  <li>When the same variable is re-instantiated again and again, the old object shall be destroyed.</li>
  <li>When I set a variable to null the the old object shall be destroyed.</li>
  <li>Array cells are null values. They shall be destroyed when parent array object has no variable to reference it.</li>
  <li>How do I free up collections? How do array rules apply?</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>public class Memory extends javax.swing.JFrame {
  
      Object[] object;
  
      private void Button1ActionPerformed(java.awt.event.ActionEvent evt) {
          object = new Object[10240000];
      }
  
      private void Button2ActionPerformed(java.awt.event.ActionEvent evt) {
          object = null;
  
          System.gc();
          System.runFinalization();
  
          //OR
  
          System.runFinalization();
          System.gc();
      }
  }
  </code></pre>