M
Malcolm Ryan
I'm writing a piece of java code which retrieves data from a database
and provides it to various parts of my program. I want to cache used
instances in memory. So as long as there are references to objects
still being used, I would keep them in the cache. This raises all
manner of garbage collection problems - how to keep track of whether
instances are still being used elsewhere in the program.
It occurs to me that Java is already keeping track of this
information, for it's own garbage colllection. What I really want to
do is ask the Java GC the question "If I released this reference,
would you garbage collect this object?". If the answer is yes, I
release the reference. If the answer is no, I hold onto it.
Is there any way of doing this?
Malcolm
and provides it to various parts of my program. I want to cache used
instances in memory. So as long as there are references to objects
still being used, I would keep them in the cache. This raises all
manner of garbage collection problems - how to keep track of whether
instances are still being used elsewhere in the program.
It occurs to me that Java is already keeping track of this
information, for it's own garbage colllection. What I really want to
do is ask the Java GC the question "If I released this reference,
would you garbage collect this object?". If the answer is yes, I
release the reference. If the answer is no, I hold onto it.
Is there any way of doing this?
Malcolm