You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by sophia <ja...@freenet.de> on 2007/07/03 18:05:03 UTC

Memory leak?

Hi 

I've got a memory problem using batik to convert swing objects to svg:

whenever I call the listed method heap increases (but never releases memory
after method has finished):

public static final void convert(JComponent swing, OutputStream out) {
		DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
		
		
		// Create an instance of org.w3c.dom.Document
		org.w3c.dom.Document document =
domImpl.createDocument("http://www.w3.org/2000/svg", "svg:svg", null);
		
		
		// Create an SVG Context to customise
		SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);

        // Create an instance of the SVG Generator
        SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
        
        swing.setSize(new
Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
        svgGenerator.setSVGCanvasSize(new
Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
        
            
       SwingSVGPrettyPrint.print(swing, svgGenerator);            	        	        
        	
       
        OutputStreamWriter writer = null;
        writer = new OutputStreamWriter(out);
        /*
		try {
			writer = new OutputStreamWriter(out,Constants.ENCODING);
		} catch (UnsupportedEncodingException e1) {
			System.out.println("Unsupported encoding");
			writer = new OutputStreamWriter(out);
		}*/
        
        try {
			svgGenerator.stream(writer, false);
			try {
				writer.flush();
				out.flush();
				writer.close();
				out.close();
				//System.out.println(out.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (SVGGraphics2DIOException e) {
			e.printStackTrace();
		} finally {
			svgGenerator.dispose();
			svgGenerator = null;
			document = null;
			domImpl = null;
		}
	  
	}

svgGenerator.dispose() has no effect. Any ideas?

-- 
View this message in context: http://www.nabble.com/Memory-leak--tf4019147.html#a11414837
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Memory leak?

Posted by th...@kodak.com.
Hi Sophia,

sophia <ja...@freenet.de> wrote on 07/04/2007 02:14:36 AM:

> I've used Java Memory Profiler. It shows that there are a lot of int[],
> byte[] and char[] arrays. If I check the instance owners it seems like 
they
> are part of an DOM. So this DOM object seems to remain in memory.

   It is normal for objects to stay in memory for a while in Java,
until Garbage collector collects them.  Can if there is a root
(global object or object on a thread's stack) that is referencing the
DOM objects.

   Does the increase in memory actually lead to an out of memory error
or do you just see heap usage growing?

> Mark Fortner-3 wrote:
> > 
> > I don't see any reason for the memory leak.  If you're running Java 6 
you
> > may want to use jconsole to profile your app and find the leak.  Here 
are
> > some docs on it:
> > 
> > http://java.sun.com/javase/6/docs/technotes/tools/share/jconsole.html
> > 
> > 
http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html
> > 
> > Hope this helps,
> > 
> > Mark
> > 
> > On 7/3/07, sophia <ja...@freenet.de> wrote:
> >>
> >>
> >> Hi
> >>
> >> I've got a memory problem using batik to convert swing objects to 
svg:
> >>
> >> whenever I call the listed method heap increases (but never releases
> >> memory
> >> after method has finished):
> >>
> >> public static final void convert(JComponent swing, OutputStream out) 
{
> >>                 DOMImplementation domImpl =
> >> GenericDOMImplementation.getDOMImplementation();
> >>
> >>
> >>                 // Create an instance of org.w3c.dom.Document
> >>                 org.w3c.dom.Document document =
> >> domImpl.createDocument("http://www.w3.org/2000/svg", "svg:svg", 
null);
> >>
> >>
> >>                 // Create an SVG Context to customise
> >>                 SVGGeneratorContext ctx =
> >> SVGGeneratorContext.createDefault(document);
> >>
> >>         // Create an instance of the SVG Generator
> >>         SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
> >>
> >>         swing.setSize(new
> >> 
Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
> >>         svgGenerator.setSVGCanvasSize(new
> >> 
Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
> >>
> >>
> >>        SwingSVGPrettyPrint.print(swing, svgGenerator);
> >>
> >>
> >>         OutputStreamWriter writer = null;
> >>         writer = new OutputStreamWriter(out);
> >>         /*
> >>                 try {
> >>                         writer = new OutputStreamWriter(out,
> >> Constants.ENCODING);
> >>                 } catch (UnsupportedEncodingException e1) {
> >>                         System.out.println("Unsupported encoding");
> >>                         writer = new OutputStreamWriter(out);
> >>                 }*/
> >>
> >>         try {
> >>                         svgGenerator.stream(writer, false);
> >>                         try {
> >>                                 writer.flush();
> >>                                 out.flush();
> >>                                 writer.close();
> >>                                 out.close();
> >>                                 //System.out.println(out.toString());
> >>                         } catch (IOException e) {
> >>                                 e.printStackTrace();
> >>                         }
> >>                 } catch (SVGGraphics2DIOException e) {
> >>                         e.printStackTrace();
> >>                 } finally {
> >>                         svgGenerator.dispose();
> >>                         svgGenerator = null;
> >>                         document = null;
> >>                         domImpl = null;
> >>                 }
> >>
> >>         }
> >>
> >> svgGenerator.dispose() has no effect. Any ideas?
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Memory-leak--tf4019147.html#a11414837
> >> Sent from the Batik - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: 
batik-users-unsubscribe@xmlgraphics.apache.org
> >> For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> >>
> >>
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/Memory-leak--
> tf4019147.html#a11425389
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Memory leak?

Posted by sophia <ja...@freenet.de>.
I've used Java Memory Profiler. It shows that there are a lot of int[],
byte[] and char[] arrays. If I check the instance owners it seems like they
are part of an DOM. So this DOM object seems to remain in memory.
 

Mark Fortner-3 wrote:
> 
> I don't see any reason for the memory leak.  If you're running Java 6 you
> may want to use jconsole to profile your app and find the leak.  Here are
> some docs on it:
> 
> http://java.sun.com/javase/6/docs/technotes/tools/share/jconsole.html
> 
> http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html
> 
> Hope this helps,
> 
> Mark
> 
> On 7/3/07, sophia <ja...@freenet.de> wrote:
>>
>>
>> Hi
>>
>> I've got a memory problem using batik to convert swing objects to svg:
>>
>> whenever I call the listed method heap increases (but never releases
>> memory
>> after method has finished):
>>
>> public static final void convert(JComponent swing, OutputStream out) {
>>                 DOMImplementation domImpl =
>> GenericDOMImplementation.getDOMImplementation();
>>
>>
>>                 // Create an instance of org.w3c.dom.Document
>>                 org.w3c.dom.Document document =
>> domImpl.createDocument("http://www.w3.org/2000/svg", "svg:svg", null);
>>
>>
>>                 // Create an SVG Context to customise
>>                 SVGGeneratorContext ctx =
>> SVGGeneratorContext.createDefault(document);
>>
>>         // Create an instance of the SVG Generator
>>         SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
>>
>>         swing.setSize(new
>> Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
>>         svgGenerator.setSVGCanvasSize(new
>> Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
>>
>>
>>        SwingSVGPrettyPrint.print(swing, svgGenerator);
>>
>>
>>         OutputStreamWriter writer = null;
>>         writer = new OutputStreamWriter(out);
>>         /*
>>                 try {
>>                         writer = new OutputStreamWriter(out,
>> Constants.ENCODING);
>>                 } catch (UnsupportedEncodingException e1) {
>>                         System.out.println("Unsupported encoding");
>>                         writer = new OutputStreamWriter(out);
>>                 }*/
>>
>>         try {
>>                         svgGenerator.stream(writer, false);
>>                         try {
>>                                 writer.flush();
>>                                 out.flush();
>>                                 writer.close();
>>                                 out.close();
>>                                 //System.out.println(out.toString());
>>                         } catch (IOException e) {
>>                                 e.printStackTrace();
>>                         }
>>                 } catch (SVGGraphics2DIOException e) {
>>                         e.printStackTrace();
>>                 } finally {
>>                         svgGenerator.dispose();
>>                         svgGenerator = null;
>>                         document = null;
>>                         domImpl = null;
>>                 }
>>
>>         }
>>
>> svgGenerator.dispose() has no effect. Any ideas?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Memory-leak--tf4019147.html#a11414837
>> Sent from the Batik - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Memory-leak--tf4019147.html#a11425389
Sent from the Batik - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Memory leak?

Posted by Mark Fortner <ph...@gmail.com>.
I don't see any reason for the memory leak.  If you're running Java 6 you
may want to use jconsole to profile your app and find the leak.  Here are
some docs on it:

http://java.sun.com/javase/6/docs/technotes/tools/share/jconsole.html

http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html

Hope this helps,

Mark

On 7/3/07, sophia <ja...@freenet.de> wrote:
>
>
> Hi
>
> I've got a memory problem using batik to convert swing objects to svg:
>
> whenever I call the listed method heap increases (but never releases
> memory
> after method has finished):
>
> public static final void convert(JComponent swing, OutputStream out) {
>                 DOMImplementation domImpl =
> GenericDOMImplementation.getDOMImplementation();
>
>
>                 // Create an instance of org.w3c.dom.Document
>                 org.w3c.dom.Document document =
> domImpl.createDocument("http://www.w3.org/2000/svg", "svg:svg", null);
>
>
>                 // Create an SVG Context to customise
>                 SVGGeneratorContext ctx =
> SVGGeneratorContext.createDefault(document);
>
>         // Create an instance of the SVG Generator
>         SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
>
>         swing.setSize(new
> Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
>         svgGenerator.setSVGCanvasSize(new
> Dimension(Constants.PRINT_OBJECT_WIDTH,Constants.PRINT_OBJECT_HEIGHT));
>
>
>        SwingSVGPrettyPrint.print(swing, svgGenerator);
>
>
>         OutputStreamWriter writer = null;
>         writer = new OutputStreamWriter(out);
>         /*
>                 try {
>                         writer = new OutputStreamWriter(out,
> Constants.ENCODING);
>                 } catch (UnsupportedEncodingException e1) {
>                         System.out.println("Unsupported encoding");
>                         writer = new OutputStreamWriter(out);
>                 }*/
>
>         try {
>                         svgGenerator.stream(writer, false);
>                         try {
>                                 writer.flush();
>                                 out.flush();
>                                 writer.close();
>                                 out.close();
>                                 //System.out.println(out.toString());
>                         } catch (IOException e) {
>                                 e.printStackTrace();
>                         }
>                 } catch (SVGGraphics2DIOException e) {
>                         e.printStackTrace();
>                 } finally {
>                         svgGenerator.dispose();
>                         svgGenerator = null;
>                         document = null;
>                         domImpl = null;
>                 }
>
>         }
>
> svgGenerator.dispose() has no effect. Any ideas?
>
> --
> View this message in context:
> http://www.nabble.com/Memory-leak--tf4019147.html#a11414837
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>