Java Code:
import java.util.Map;
import java.util.WeakHashMap;

public class Weak {

  public static void main(String args[]) {
    final Map map = new WeakHashMap();
    map.put(new String("Java-Forums"), "www.java-forums.org");
    Runnable runner = new Runnable() {
      public void run() {
        while (map.containsKey("Java-Forums")) {
          try {
            Thread.sleep(500);
          } catch (InterruptedException ignored) {
          }
          System.out.println("Waiting");
          System.gc();
        }
      }
    };
    Thread t = new Thread(runner);
    t.start();
    System.out.println("Main waiting");
    try {
      t.join();
    } catch (InterruptedException ignored) {
    }
  }
}