Vincent said:
I think nobody understood the problem : What I want to know is wether or not
my object is reachable.
There is no way to find this out. It's simply not feasible. To
suddenly determine whether an object is reachable on demand would
require insane amounts of work. It could take several seconds for some
applications. The only reason most garbage collection algorithms are at
all workable is that they defer this work.
A WeakReference will be cleared as soon as the VM realizes that the
object isn't reachable through other means. Therefore, you *can* find
out whether the VM has determined that the object is unreachable or not
-- and WeakReference is one way to do it. However, it's always possible
that the VM has not yet realized that the object isn't reachable. There
is no way in Java to force the VM to do a full garbage collection and
check that, although System.gc suggests that it try.
--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation