I easily reproduced the behavior you described with XXE V2.11, Java
1.4.2_09 on Linux. (I didn't manage to reproduce the problem with V3 and
Java 1.5.0_05, which seems faster and more constant in terms of garbage
collection.)

After a sequence of close/open, I used Help|About to display memory
usage. The Help|About dialog box does a garbage-collection before
displaying the memory usage.

My analysis is that there is no memory leak here. I think that due to
the way XXE works, *transient* out of memory errors may happen when
opening a document containing large images.

Why do I say that? Because after getting the message "Out of memory"
displayed in the document view in red near the ``broken image'' icon,
using Select|Redraw caused all the images to be properly displayed
again. And after that, Help|About reported that there were still plenty
of memory available.

In summary, a 1Mb JPEG image has say 1482x1704 pixels. Once uncompressed
each pixel uses 4 bytes (RGBA -- or is it 3 bytes: RGB?). This makes
9.63Mb per image. 4 images means 38Mb. To be on the safe side with XXE,
you'll need say 2.5*38Mb=95Mb.

No, I'm no ashamed to say this, because the workaround is so obvious:

* A 1482x1704 pixels is totally unusable on screen: much too large.

* Simply adjust the CSS style sheet to display images scaled down
(example: CSS style sheet "Images displayed as thumbnails") or define an
element template for <imagedata> having for example: scalefit=1, width=50%.

With CSS stylesheet  "Images displayed as thumbnails", a document which
caused XXE to use 36Mb (document data+XXE code+many plug-in code, etc) /
63Mb, now only uses 7Mb/63Mb.

Christian K?hrt wrote:
> thanks a lot for your fast reply. I will try to explain what I am doing
> to provocate the out of memory exception.
> 
> java version: 1.4.2_08
> os: win xp
> software to observe the memory of the vm: JProbe
> startoptions of xxe: starting without the increase of memory heap and
> allocated memory
> 
> workflow:
> 1. creating a new docbook article
> 2. insert 4 images (jps's around 1mb each) as references in the local
> filesystem
> 3. save
> 4. close the document
> .... used memory of vm increased from 4mb to 47mb (after the garbage
> collector runs)
> 5. open the same document
> ... huge increase of used memory again
> 6. the first image can be displayed all the others not ... only the
> message instead of the image java.lang.outOfMemory
> 
> I can increase the reserved memory by adding the vm options -Xss1m
> -Xmx128m but now it is only a question of time when the first out of
> memory occured (4 times open - close procedure)
> 
> do you still need the document? its only a docbook article with 4
> figures and this figures are references in the local filesystem and they
> are around 1mb sized jpg images.
> 
> the out of memory also occured without using jprobe.
> 
> like mentioned in my first mail we are planing to integrate xxe in
> another application and out of memory exceptions are not really funny.


Reply via email to