Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bloch.item6;
- import java.util.Map;
- import java.util.WeakHashMap;
- /**
- * Created by bubu on 4/19/14.
- */
- public class TestDriver {
- public static void main(String[] args) {
- Map<Object, String> map = new WeakHashMap<>();
- Object c1 = new Object();
- map.put(c1, "1");
- c1 = null;
- for (int i = 0; i < 100000; i++) {
- if (map.size() != 0) {
- System.out.println("At iteration " + i + " the map still holds the reference on someDataObject");
- } else {
- System.out.println("somDataObject has finally been garbage collected at iteration " + i + ", hence the map is now empty");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement