[jdom-interest] JDOM and memory
mike at saxonica.com
Mon Jan 23 08:59:35 PST 2012
On 23/01/2012 16:28, Rolf Lear wrote:
> 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>
And that suggests to me that it is a bad idea.
The class hierarchy should reflect "is-a" relationships, it shouldn't be
designed to tweak performance. It's not true that an Element and its
contents are the same thing, therefore it's wrong to treat them as being
the same object. It will only lead to confusion.
You can achieve the memory saving by having Element.getChildren() create
the returned List object dynamically (it doesn't need to copy any data
to achieve this).
> The logical thing to do would be to deprecate addContent(Collection)
I don't think that solves the problem. There will be cases where
existing code fixes up to the wrong method, and ends up adding the
children of an element to a new parent rather than adding the element
More information about the jdom-interest