Re: System.gc not enqueuing cleared WeakReferences



Ian Pilcher wrote:
I have (finally!) reached the point of writing unit tests for my
WeakIdentityHashMap, and testing for proper removal of otherwise
unreachable keys is proving to be quite a problem.

Currently, my tests assume that a call to System.gc() will ensure that
all cleared WeakReferences will be enqueued, but this does not appear to
be the case.

Does this sound credible? (This is Sun's 1.5.0_06 JVM on Linux, BTW.)

References are not guaranteed to be enqueued immediately after they are cleared. In Sun's implementation all references get passed through a maximum priority thread before becoming enqueued. A further complication with UNIX threading is that, unless the process is run as root, the thread priority is apparently ignored.


If System.gc() won't do the trick, does anyone know of anyway to ensure
that all WeakReferences are actually enqueued?

I have a suspicion that References objects that are dropped themselves or only referenceable via WeakReferences do not get enqueued. That was on my list of things to check...


Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
.