[jdom-interest] Re: carrying user data around with Element

David Churchville dmc at clearlight.com
Thu Nov 16 17:53:26 PST 2000


> My primary objection is reducing necessary memory consumption.
> As such, I'm concerned about adding a 32-bit pointer to every element.
> It seems like a pretty heavy price for something that's not generally
> needed and could be solved in other ways.  (Looking at one 300K XML file
> I have here with 11K elements that would be 44K added memory, or 15% of
> the original XML file size.)

OK, that's actually a reasonable objection :-)

>
> Now, just brainstorming here, it would be theoretically possible to do
> this:
>
> Object getUserData() {
>   return GlobalUserDataHash.get(this);
> }
>
> This has the advantage that only elements with data take up memory, and
> GUDH could use weak refs to enable GC.  But that seems like quite a
> hack.

Actually, this solves the problem nicely, I think.

To refine your suggestion, this "GUDH" could be on the Document object
(since every element carries this around anyway).  Its not really a hack,
more of a Flyweight pattern of sorts.  I think that user objects have proven
themselves in API land, in spite of being "slightly less than ideal".  In
the spirit of pragmatism that JDOM embodies, having this capability, and
having it cheaply (in terms of memory and code impact) sounds suspiciously
like WIN, WIN.

--Dave






More information about the jdom-interest mailing list