P
Paul J. Lucas
So the idea is to use WeakReferences to objects. When the GC
decides to GC said objects, I'd like a thread to be notified
via a ReferenceQueue that the objects are about to be GC'd. The
thread can then write them out to disk. The upshot of all this
would be to implement a disk cache for objects.
The problem is, in reading the documentation for WeakReference,
that all WeakReferences are cleared prior to being enqueued
onto ReferenceQueues. That means the code that does either the
poll() or remove() will always get a reference with null for
the referrent value of get().
That's annoying. Ideally, I want the thread to be able to get
at the object just before it's GC'd so it can be written out to
disk.
So is it possible to do something like I want (i.e., be given a
reference to an object about to be GC'd so I can do one last
thing with it)? If so, how?
- Paul
decides to GC said objects, I'd like a thread to be notified
via a ReferenceQueue that the objects are about to be GC'd. The
thread can then write them out to disk. The upshot of all this
would be to implement a disk cache for objects.
The problem is, in reading the documentation for WeakReference,
that all WeakReferences are cleared prior to being enqueued
onto ReferenceQueues. That means the code that does either the
poll() or remove() will always get a reference with null for
the referrent value of get().
That's annoying. Ideally, I want the thread to be able to get
at the object just before it's GC'd so it can be written out to
disk.
So is it possible to do something like I want (i.e., be given a
reference to an object about to be GC'd so I can do one last
thing with it)? If so, how?
- Paul