I use RefQueue, to track which WeakRef's are not pointing to object anymore. But I'm wonering how it works. When I tell WeakReference to register it self in particular queue, and then after some time I do:
private void removeDumpReferences() {
Reference<? extends E> ref = null;
while ((ref = garbageQueue.poll()) != null) {
list.remove(ref);
}
}
Does it runs through all registered references (testing whether ref points on null), or there are too queues in fact one for registered one's and second for those which GC considered as "not-in use" anymore? Or maybe it works very different way?