[jdom-interest] Recycling jdom elements ?
paul at activemath.org
Mon Sep 5 13:37:01 PDT 2005
Le 5 sept. 05, à 20:45, Tatu Saloranta a écrit :
> --- Paul Libbrecht <paul at activemath.org> wrote:
>> I will call System.gc() programmatically later...
> This probably won't help with OutOfMemory cases -- GC
> is always called before this exception is thrown.
> Problem is probably the temporary processing memory
> usage, or with too low heap size settings for JVM,
> things GC has not control over.
Interesting... I think that, then, this gc call at OutOfMemoryError is
>> but in the meantime,
>> I realize that it would be very meaningful to
>> recycle JDOM elements
>> (and, in particular, lists in them) instead of
>> garbage-collecting them.
> Recycling would actually increase memory usage
> (temporary storage of objects to be recycled uses
> memory that GC can not touch; unless done using
> special [weak?] references, something which is quite
> expensive compared to simple object creation).
> With newer JVMs, object recycling is also often a bad
> idea (generational GC assumes majority of objects are
> short-lived; long-lived ones are more expensive to
> reclaim); this has been gradually changing since days
> of 1.0.2, when object recycling made more sense.
> This seems to be the general consensus, at least;
> object pools are most useful with objects that are
> expensive to create (DB connections etc.), and less so
> with temporary objects.
But how would you explain, then, the fact that I can avoid the
OutOfMemoryError by calling gc() regularly!
I can only explain this by the fact that gc() takes time (probably too
much time) to trigger elect JDOM objects to gc().
Long ago when I tried profiling, I tended to end with thousands of
Re-using the elements would avoid having them hanging around as they
would be quicker made eligible for re-use (i.e. with a call at
controlled place as opposed to "with the result of the search of the
Remember that a JDOM element is not just an object with a few
variables. Eaach element has an amount of lists attached, each being
ArrayLists (I think) and each being doubled several times while
More information about the jdom-interest