title: Why Java System.gc() not working as expected?
body: <p>I have two functions below one is insert() and other one is startGC().</p>
  
  <p>I will call insert() method first which will take some 300MB of heap space.
  After that I will call startGC() which should release the memory allocated in heap because all the vector objects are local to the function but its not happening.</p>
  
  <pre><code>private void insert()
   {
           Vector v=new Vector();
           Vector v1=new Vector();
           Vector v2=new Vector();
          String str="Hello";
  
          for (long i = 0L; i &lt; 999999L; i++) {
              v.add(str + i);
              v1.add(str + i);
              v2.add(str + i);
          }
          v=null;
          v1=null;
          v2=null;
   }
  
  private void startGC()
  {
      System.gc();
  }
  </code></pre>
  
  <p><strong>My Question:</strong></p>
  
  <p>1) Why Garbage collect is not working in this example.</p>
  
  <p>2) How to make JVM to garbage collect all unused memory blocks.</p>
  
  <p><strong>Any code sample to achieve the same.</strong></p>