I am working on an applet that includes a JTable that
has a column displaying 2D structure diagrams (I use
CDK to render the structures). It all works very
nicely until the user tries to load a few thousand
compounds into the applet - the result is an out of
I did some memory profiling with JMP
<http://www.khelekore.org/jmp/> and jProfiler
and discoverd that the ChemObject class initializes
many empty fields that are seldom/never used but that
consume considerable amounts of memory (as they are
Vectors, Hashtables or Arrays).
I modified ChemObject to initialize these fields to
null and delay creation of them until they are needed
(lazy creation). This significantly reduced memory
consumption: 3214 compounds went from consuming 156M
down to 39M after implementing lazy creation.
Attached is the modified ChemObject.java (&
CDKConstants.java). I also reduced the initial sizes
of the pointers and flags arrays and made the fields
private (even subclasses should use the getter/setter
methods rather than access fields directly).
The unit tests all pass.