M
Mark M
I have read a lot of material on weak/soft/phantom references, but
they do not seem to solve a common memory problem we have. I must be
missing something about how weak references work. Here is the
problem:
We have large in-memory objects that cannot be recreated from the
original source. They can however, be persisted to disk and
reconstructed, but it is very expensive to do so.
We need to have the JVM collect these objects when memory runs low,
but we don't want to pay the cost of putting them to disk unless it is
necessary.
Weak references do not seem to solve this problem because they seem to
assume that the object can be re-created at any time. We must know
ahead of time that the object is going to be disposed so we can save
it to disk first. E.g. the weak reference (via the ReferenceQueue)
only tells us *after* the object finializer has been run and the
object has been made un-referenceable (is that a word)? At this point
we cannot get a (hard) reference to the object to persist it... it is
too late. The get() method on the Reference object will always return
null at this point.
We also cannot do the write-to-disk during in the object finalizer
because the object does not know why it is being finialized (if due to
a weak reference being cleared, it should persist itself to disk, if
due to being unreferenced, it should do nothing because it is leaving
the JVM forever).
How can we get control over when to persist the object to disk before
it gets collected? We cannot afford to persist every such object to
disk with the idea that sometime it might need to be reconstructed.
Thanks for any ideas...
-Mark
they do not seem to solve a common memory problem we have. I must be
missing something about how weak references work. Here is the
problem:
We have large in-memory objects that cannot be recreated from the
original source. They can however, be persisted to disk and
reconstructed, but it is very expensive to do so.
We need to have the JVM collect these objects when memory runs low,
but we don't want to pay the cost of putting them to disk unless it is
necessary.
Weak references do not seem to solve this problem because they seem to
assume that the object can be re-created at any time. We must know
ahead of time that the object is going to be disposed so we can save
it to disk first. E.g. the weak reference (via the ReferenceQueue)
only tells us *after* the object finializer has been run and the
object has been made un-referenceable (is that a word)? At this point
we cannot get a (hard) reference to the object to persist it... it is
too late. The get() method on the Reference object will always return
null at this point.
We also cannot do the write-to-disk during in the object finalizer
because the object does not know why it is being finialized (if due to
a weak reference being cleared, it should persist itself to disk, if
due to being unreferenced, it should do nothing because it is leaving
the JVM forever).
How can we get control over when to persist the object to disk before
it gets collected? We cannot afford to persist every such object to
disk with the idea that sometime it might need to be reconstructed.
Thanks for any ideas...
-Mark