-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Tegiri Nenashi schreef:
|> Well, you’re completely ignoring Joshua’s argument:
|>
|> |> 2 involves less bookkeeping, and so is more robust.
|>
|> Your solution involves a lot of bookkeeping.
|
| Let see. In fancy reference scenario you have a reference that can
| become invalid at any given time. Your application have to check it
| for null and delete it from collection.
No it does not. It disappears automagically.
Do you imply a weak reference would disappear from collection?
String[] str = new String[1000000];
str[0] = "abc";
WeakReference<String[]> r = new WeakReference<String[]>(str);
LinkedList<WeakReference<String[]>> l = new
LinkedList<WeakReference<String[]>>();
l.add(r);
str = null;
System.gc();
WeakReference<String[]> tmp = l.getFirst(); // NoSuchElementException?
String[] tmp1 = tmp.get();
System.out.println(tmp1[0]);
If LinkedList were purged of null WeakReferences, the it should throw
NoSuchElementException, but it throws NPE a line after that. Sure
collections of WeakReferences are not automatically managed, except
maybe dedicated ones.