[jdom-interest] JDOM and memory

Rolf Lear jdom at tuis.net
Mon Jan 23 08:28:37 PST 2012

Hi all.

I have started on this memory optimization, and it is still in early
stages. There is one API issue though:

The Element API has the two methods:

addContent(Content node)
addContent(Collection<? extends Content> newContent)

if I make Element implement List<Content> (which is what this
memory-change will do), then the above two methods become ambiguous because
Element will be both Content and List<Content>

The logical thing to do would be to deprecate addContent(Collection) since
the List.addAll(Collection ...) is the obvious substitute.

In the interim people migrating from JDOM 1.x will have compile errors,
and will have to either:
1. choose to change all addContent() calls where the content is Element to
either add(element), or addAll(element) to add the element or it's content
respectively... - which would make no sense because that would guarantee an
exception because you cannot add an Element's content to some other element
without first detaching it.

The bottom line is that all the addContent* methods are equivalent to the
regular List.add* methods.... and there is no ambiguity in those, it is
either add(Content) or addAll(Collection...)

So far the results look promising. I have a baseline memory footprint that
I am aiming to improve on, and when I have results it will be easier to
discuss whether the changes would be worth the improvements.

But, for now, it would seem impossible to merge ContentList in to Element
without some compatibility problems...


On Mon, 02 Jan 2012 15:27:40 -0500, Rolf <jdom at tuis.net> wrote:
> Hi all.
> Memory optimization has never been a top priority for JDOM. At the same 
> time, for what it does, JDOM is not a 'terrible' memory user. Still, I 
> have done some analysis, and, I believe I can trim about a quarter to a 
> half of 'JDOM Overhead' memory usage by making two 'simple' changes....
> The first is to merge the ContentList class in to the Element class (and

> also in to Document). ....

More information about the jdom-interest mailing list