-
-
Save paulogaspar7/8539858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WeakHashMap<Integer, String> map = new WeakHashMap<Integer, String>(); | |
map.put(new Integer(10), "aaa"); // remove entry | |
// map.put(10, "aaa"); // don't remove entry | |
// map.put(Integer.valueOf(10), "aaa"); // don't remove entry | |
for (int i = 0; i < Integer.MAX_VALUE; i++) { | |
if (map.size() != 0) { | |
System.out.println("At iteration " + i + " the map still holds the reference to object"); | |
} else { | |
System.out.println("Object has finally been garbage collected at iteration " + i + ", the map is now empty"); | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment