public static void force(){
  Object obj=new Object();
  WeakReference<Object> ref=new WeakReference<Object>(obj);
  obj=null;
  while (ref.get() != null) {
    System.gc();
  }
}

public static void force ( ) { Object obj = new Object ( ) ; WeakReference < Object > ref = new WeakReference < Object > ( obj ) ; obj = null ; while ( ref . get ( ) != null ) { System . gc ( ) ; } }
try to force gc once by repeatedly calling system . gc ( ) until our weak reference disappears this could cause multiple gcs until our object is actually collected
