Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weak References in a Set

Kalichar Rangantittu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Education required:
If I have a Collection (note not necessarily a WeakHashMap) and I want to store references that will be GCs and are weak as follows:
Set s = new HashSet();
String str = new String("Hello World");
s.add(new WeakReference(str));
str = null;
..Loop though Set and print the contents of the weak reference.
The output will mostly be null. The problem I want to eleminate is to remove the WeakReference itself from the set, otherwise the set's size is 1. I want the set size to go back to 0. Dont want to create my own WeakHashSet if I can avoid it .
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic