Memory leak in Batik 1.0 JPEG-Transcoder ?

We're working on an application that generates charts on the fly.
The application generates an svg document and uses the batik transcoder api
to transcode it into a jpeg (Batik 1.0 final). We noticed that after a 
certain amout of requests the application is stopping with an 
OutOfMemoryError.

We used JProbe to analyze where the memory leak comes from. We suspected 
it came from the jpeg transcoder. To make sure we wrote a simple test 
class that does nothing else but transcode one svg document again and 
again and again. The code is below.
(Ok, the code is not really beatiful but that should't consume memory ;-) )
The used svg document is not very complex and about 15KByte in size. See 
below.

After about the 115th transcoding the JVM memory (64MByte) is used up and 
the OutOfMemoryError Exception occurs. According to JProbe most of the 
memory is used by int[]. Unfortunately JProbe is unable to tell _where_ 
exactly all the int[] are allocated.

Regards,
Markus Huehn

<---- code sniplet --

public class ChartTransformer extends java.lang.Object {

    public ChartTransformer() {
    }

    byte[] getDocument(String pURL) {
        StringBuffer sb=new StringBuffer();
        int b;
        InputStream fis;
        try {
            fis = new java.io.FileInputStream("D:\\temp\\test_svg.xml");
            b=fis.read();
            while(b!=-1) {
                sb.append((char)b);
                b=fis.read();
            }
            fis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sb.toString().getBytes();
   }
   
    void transcode(OutputStream pOs, String pURL, float pJpegQuality) {
        byte[] svgChart = getDocument(pURL);

        try {
            Float myJpegQuality = new Float(pJpegQuality);
            
            org.apache.batik.transcoder.TranscoderInput input   = new 
org.apache.batik.transcoder.TranscoderInput(new ByteArrayInputStream
(svgChart));
            org.apache.batik.transcoder.TranscoderOutput output = new 
org.apache.batik.transcoder.TranscoderOutput(pOs);
            org.apache.batik.transcoder.image.JPEGTranscoder 
jpegTranscoder = new org.apache.batik.transcoder.image.JPEGTranscoder();
            
            jpegTranscoder.addTranscodingHint
(org.apache.batik.transcoder.image.JPEGTranscoder.KEY_QUALITY, 
myJpegQuality);
            jpegTranscoder.addTranscodingHint
(org.apache.batik.transcoder.image.JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
 "org.apache.crimson.parser.XMLReaderImpl");
            jpegTranscoder.transcode(input, output);
            
            myJpegQuality       = null;
            input               = null;
            svgChart            = null;
            output              = null;
            jpegTranscoder      = null;

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(java.lang.String[] args) {
        for(int i=0;i<300;i++){
            try{
                ChartTransformer ct = new ChartTransformer();
                java.io.FileOutputStream fos = new java.io.FileOutputStream
("D:\\temp\\pic.jpg");
                ct.transcode((java.io.OutputStream)fos,"test_svg.xml",
(float)0.5);
                fos.close();
                ct = null;
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }
        System.exit(0);
    }
    
}

---- end code sniplet -->

<---- svg document --

<?xml version="1.0" encoding="UTF-8"?>
<svg height="430" width="955.7142857142858">
<rect height="430" width="955.7142857142858" y="0" x="0" 
style="fill:#cccccc"/>
<line y2="320" x2="56" y1="20" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<line y2="20" x2="901.7142857142858" y1="320" x1="901.7142857142858" 
style="fill:none; stroke:black; stroke-width:1"/>
<line y2="340" x2="36" y1="40" x1="36" style="fill:none; stroke:black; 
stroke-width:1"/>
<polygon points="36,340 56,320 901.7142857142858,320 
881.7142857142858,340" style="fill:grey;"/>
<text style="font-size:10; text-anchor:middle;" y="15" x="56">km</text>
<text style="font-size:10;" y="325" x="906.7142857142858">Fahrzeug</text>
<rect height="15" width="15" y="395" x="20" style="fill:#ffff00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="35,410 40,405 40,390 35,395" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="20,395 35,395 40,390 25,390" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10;" y="405" x="50">Gesamt-Strecke</text>
<line y2="320" x2="901.7142857142858" y1="320" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="340" x2="36" y1="320" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="345" x="31">0</text>
<line y2="270" x2="901.7142857142858" y1="270" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="290" x2="36" y1="270" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="295" x="31">10000</text>
<line y2="220" x2="901.7142857142858" y1="220" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="240" x2="36" y1="220" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="245" x="31">20000</text>
<line y2="170" x2="901.7142857142858" y1="170" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="190" x2="36" y1="170" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="195" x="31">30000</text>
<line y2="120" x2="901.7142857142858" y1="120" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="140" x2="36" y1="120" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="145" x="31">40000</text>
<line y2="70" x2="901.7142857142858" y1="70" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="90" x2="36" y1="70" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="95" x="31">50000</text>
<line y2="20" x2="901.7142857142858" y1="20" x1="56" style="fill:none; 
stroke:black; stroke-width:1"/>
<line y2="40" x2="36" y1="20" x1="56" style="fill:none; stroke:black; 
stroke-width:1"/>
<text style="font-size:10; text-anchor:end;" y="45" x="31">60000</text>
<line y2="136.73944444444444" x2="896.7142857142858" 
y1="136.73944444444444" x1="51" style="fill:#ffff00; stroke:#ffff00; 
stroke-width:2"/>
<rect height="174.105" width="22.857142857142858" y="160.895" 
x="63.85714285714286" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="86.71428571428572,335 96.71428571428572,325 
96.71428571428572,150.895 86.71428571428572,160.895" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="63.85714285714286,160.895 86.71428571428572,160.895 
96.71428571428572,150.895 73.85714285714286,150.895" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="75.28571428571429">17</text>
<rect height="214.725" width="22.857142857142858" y="120.275" 
x="109.57142857142857" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="132.42857142857142,335 142.42857142857142,325 
142.42857142857142,110.275 132.42857142857142,120.275" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="109.57142857142857,120.275 132.42857142857142,120.275 
142.42857142857142,110.275 119.57142857142857,110.275" 
style="fill:#b2b200; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" x="121">27</text>
<rect height="231.885" width="22.857142857142858" y="103.11500000000001" 
x="155.28571428571428" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="178.14285714285714,335 188.14285714285714,325 
188.14285714285714,93.11500000000001 
178.14285714285714,103.11500000000001" style="fill:#7c7c00; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<polygon points="155.28571428571428,103.11500000000001 
178.14285714285714,103.11500000000001 188.14285714285714,93.11500000000001 
165.28571428571428,93.11500000000001" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="166.7142857142857">16</text>
<rect height="226.75" width="22.857142857142858" y="108.25" x="201" 
style="fill:#ffff00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="223.85714285714286,335 233.85714285714286,325 
233.85714285714286,98.25 223.85714285714286,108.25" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="201,108.25 223.85714285714286,108.25 
233.85714285714286,98.25 211,98.25" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="212.42857142857142">89</text>
<rect height="203.22" width="22.857142857142858" y="131.78" 
x="246.71428571428572" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="269.57142857142856,335 279.57142857142856,325 
279.57142857142856,121.78 269.57142857142856,131.78" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="246.71428571428572,131.78 269.57142857142856,131.78 
279.57142857142856,121.78 256.7142857142857,121.78" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="258.14285714285717">35</text>
<rect height="219.875" width="22.857142857142858" y="115.125" 
x="292.42857142857144" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="315.2857142857143,335 325.2857142857143,325 
325.2857142857143,105.125 315.2857142857143,115.125" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="292.42857142857144,115.125 315.2857142857143,115.125 
325.2857142857143,105.125 302.42857142857144,105.125" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="303.8571428571429">31</text>
<rect height="242.79500000000002" width="22.857142857142858" 
y="92.20499999999998" x="338.14285714285717" style="fill:#ffff00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="361,335 371,325 371,82.20499999999998 
361,92.20499999999998" style="fill:#7c7c00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="338.14285714285717,92.20499999999998 
361,92.20499999999998 371,82.20499999999998 
348.14285714285717,82.20499999999998" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="349.5714285714286">47</text>
<rect height="163.05" width="22.857142857142858" y="171.95" 
x="383.8571428571429" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="406.7142857142857,335 416.7142857142857,325 
416.7142857142857,161.95 406.7142857142857,171.95" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="383.8571428571429,171.95 406.7142857142857,171.95 
416.7142857142857,161.95 393.8571428571429,161.95" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="395.28571428571433">49</text>
<rect height="176.595" width="22.857142857142858" y="158.405" 
x="429.5714285714286" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="452.42857142857144,335 462.42857142857144,325 
462.42857142857144,148.405 452.42857142857144,158.405" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="429.5714285714286,158.405 452.42857142857144,158.405 
462.42857142857144,148.405 439.5714285714286,148.405" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="441.00000000000006">60</text>
<rect height="146.805" width="22.857142857142858" y="188.195" 
x="475.28571428571433" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="498.14285714285717,335 508.14285714285717,325 
508.14285714285717,178.195 498.14285714285717,188.195" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="475.28571428571433,188.195 498.14285714285717,188.195 
508.14285714285717,178.195 485.28571428571433,178.195" 
style="fill:#b2b200; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="486.7142857142858">34</text>
<rect height="83.775" width="22.857142857142858" y="251.225" x="521" 
style="fill:#ffff00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="543.8571428571429,335 553.8571428571429,325 
553.8571428571429,241.225 543.8571428571429,251.225" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="521,251.225 543.8571428571429,251.225 
553.8571428571429,241.225 531,241.225" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="532.4285714285714">30</text>
<rect height="77.915" width="22.857142857142858" y="257.085" 
x="566.7142857142857" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="589.5714285714286,335 599.5714285714286,325 
599.5714285714286,247.08499999999998 589.5714285714286,257.085" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="566.7142857142857,257.085 589.5714285714286,257.085 
599.5714285714286,247.08499999999998 576.7142857142857,247.08499999999998" 
style="fill:#b2b200; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="578.1428571428571">40</text>
<rect height="249.51000000000002" width="22.857142857142858" 
y="85.48999999999998" x="612.4285714285714" style="fill:#ffff00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="635.2857142857143,335 645.2857142857143,325 
645.2857142857143,75.48999999999998 635.2857142857143,85.48999999999998" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="612.4285714285714,85.48999999999998 
635.2857142857143,85.48999999999998 645.2857142857143,75.48999999999998 
622.4285714285714,75.48999999999998" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="623.8571428571429">67</text>
<rect height="209.195" width="22.857142857142858" y="125.805" 
x="658.1428571428571" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="681,335 691,325 691,115.805 681,125.805" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="658.1428571428571,125.805 681,125.805 691,115.805 
668.1428571428571,115.805" style="fill:#b2b200; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="669.5714285714286">65</text>
<rect height="216.19" width="22.857142857142858" y="118.81" 
x="703.8571428571429" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="726.7142857142858,335 736.7142857142858,325 
736.7142857142858,108.81 726.7142857142858,118.81" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="703.8571428571429,118.81 726.7142857142858,118.81 
736.7142857142858,108.81 713.8571428571429,108.81" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="715.2857142857143">64</text>
<rect height="225.155" width="22.857142857142858" y="109.845" 
x="749.5714285714286" style="fill:#ffff00; stroke:black; stroke-
linejoin:round; stroke-width:1"/>
<polygon points="772.4285714285714,335 782.4285714285714,325 
782.4285714285714,99.845 772.4285714285714,109.845" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="749.5714285714286,109.845 772.4285714285714,109.845 
782.4285714285714,99.845 759.5714285714286,99.845" style="fill:#b2b200; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" x="761">78</text>
<rect height="250.38500000000002" width="22.857142857142858" 
y="84.61499999999998" x="795.2857142857142" style="fill:#ffff00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="818.1428571428571,335 828.1428571428571,325 
828.1428571428571,74.61499999999998 818.1428571428571,84.61499999999998" 
style="fill:#7c7c00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="795.2857142857142,84.61499999999998 
818.1428571428571,84.61499999999998 828.1428571428571,74.61499999999998 
805.2857142857142,74.61499999999998" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="806.7142857142857">74</text>
<rect height="76.76" width="22.857142857142858" y="258.24" x="841" 
style="fill:#ffff00; stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="863.8571428571429,335 873.8571428571429,325 
873.8571428571429,248.24 863.8571428571429,258.24" style="fill:#7c7c00; 
stroke:black; stroke-linejoin:round; stroke-width:1"/>
<polygon points="841,258.24 863.8571428571429,258.24 
873.8571428571429,248.24 851,248.24" style="fill:#b2b200; stroke:black; 
stroke-linejoin:round; stroke-width:1"/>
<text style="font-size:10; text-anchor:middle;" y="355" 
x="852.4285714285714">75</text>
</svg>

---- end svg document -->


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to