T
Thomas Kellerer
Hello,
I'm using a SoftReference to a StringBuffer to build up log messages that are
later displayed in a Swing GUI. As this might potentially grow but I don't want
the messages to be causing an OOME (as most of them will be written into the log
file anyway) I am storing the actual StringBuffer in a SoftReference.
My understand was, that a SoftReference will not be collected until the JVM runs
out of memory. But it seems that when I run a lengthy task that does create a
lot of temporary objects, the soft reference is cleared even though the
available memory (max heap) is big enough.
The only explanation I have: the JVM will already collect SoftReferences before
even expanding the current heap (even if way below the -Xmx value), or - even
worse - just at will
Can anybody shed some light on this?
Currently this does not really help me with my problem. Is there anyway to
implement an object that *only* gets collected if the JVM cannot expand the heap
any more (-Xmx reached)?
Regards
Thomas
I'm using a SoftReference to a StringBuffer to build up log messages that are
later displayed in a Swing GUI. As this might potentially grow but I don't want
the messages to be causing an OOME (as most of them will be written into the log
file anyway) I am storing the actual StringBuffer in a SoftReference.
My understand was, that a SoftReference will not be collected until the JVM runs
out of memory. But it seems that when I run a lengthy task that does create a
lot of temporary objects, the soft reference is cleared even though the
available memory (max heap) is big enough.
The only explanation I have: the JVM will already collect SoftReferences before
even expanding the current heap (even if way below the -Xmx value), or - even
worse - just at will
Can anybody shed some light on this?
Currently this does not really help me with my problem. Is there anyway to
implement an object that *only* gets collected if the JVM cannot expand the heap
any more (-Xmx reached)?
Regards
Thomas