Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. package com.bloch.item6;
  2.  
  3. import java.util.Map;
  4. import java.util.WeakHashMap;
  5.  
  6. /**
  7.  * Created by bubu on 4/19/14.
  8.  */
  9. public class TestDriver {
  10.     public static void main(String[] args) {
  11.         Map<Object, String> map = new WeakHashMap<>();
  12.         Object c1 = new Object();
  13.         map.put(c1, "1");
  14.  
  15.         c1 = null;
  16.  
  17.         for (int i = 0; i < 100000; i++) {
  18.             if (map.size() != 0) {
  19.                 System.out.println("At iteration " + i + " the map still holds the reference on someDataObject");
  20.             } else {
  21.                 System.out.println("somDataObject has finally been garbage collected at iteration " + i + ", hence the map is now empty");
  22.                 break;
  23.             }
  24.         }
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement