[jdom-interest] Recycling jdom elements ?

Tatu Saloranta cowtowncoder at yahoo.com
Mon Sep 5 11:45:35 PDT 2005

--- Paul Libbrecht <paul at activemath.org> wrote:

> Hi,
> My little experience:
> Since I introduced jdom parsing, xpath evaluation,
> modification, and 
> output in my process (which was purely text based
> originally, 
> processing fine thousands of text snippets), I am
> starting to get 
> OutOfMemoryErrors... This is all running inside Ant
> itself inside jEdit 
> and, in there, I am able to invoke System.gc() by a
> click. I am able to 
> avoid the OutOfMemoryError by doing enough of these
> clicks (a bit 
> sporty sometimes).
> 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.

> 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 then again, it doesn't hurt if you would want to
try it out, and measure to see if you do get benefits.
I don't recall others doing it lately, but you can
check out mailing list archives to be sure?

-+ Tatu +-

Click here to donate to the Hurricane Katrina relief effort.

More information about the jdom-interest mailing list