Hi, There might be a memory leak when rendering embedded images in Batik.
I am working on Windows 2000 SP4 and JDK 1.3.1. Using CVS Batik from 6/24/03, I start an instance of the JSVGCanvas and set it to be be dynamic. I add a node with the following SVG properties: <image x="0" y="0" width="2700.0" image-rendering="optimizeQuality" xlink:href="blah.png" height="1813.0" preserveAspectRatio="xMinYMin meet"/> In this case, blah.png is about 150k. It is a black and white drawing of size 1813x2700. It has been optimized with the optipng png optimizer. [ http://www.cs.toronto.edu/~cosmin/pngtech/optipng/ ] After initial rendering, the app uses ~35 megs. I do a series of zooms and add more elements. The memory footprint rises to ~100 megs. If I just quit here ( set my SVGCanvas to null ), I see that memory is never freed. 1. ) I purge the canvas. ( most of this code from Randy Baron's May 5, 2003 post 'JSVGCanvas disposal / memory leak' ). public void purge() { ToolTipManager ttipman = ToolTipManager.sharedInstance(); ttipman.unregisterComponent(this); this.renderer.dispose(); this.releaseRenderingReferences(); this.getOverlays().clear(); this.getInteractors().clear(); this.bridgeContext.dispose(); if (this.getUpdateManager() != null && this.getUpdateManager().getBridgeContext() != null) this.getUpdateManager().getBridgeContext().dispose(); this.stopProcessing(); this.getGraphics().dispose(); this.flushImageCache(); this.deselectAll(); this.removeAll(); this.listener = null; this.listenerList = null; this.updateManager = null; this.accessibleContext = null; this.svgDocument = null; this.removeMouseListener(mouseListener); Runtime.getRuntime().runFinalization(); Runtime.getRuntime().gc(); /* in the original code, there is a nullOut Function, but I want to retain my SVG's XML, so I do the dispose() call below instead */ } 2.) After a little tracing, I add a dispose function to org.apache.batik.gvt.RasterImageNode. public void dispose{ this.image = null; // image in RasterImageNode.java is declared as protected Filter image; } I invoking dispose on the my image node ( blah.png , above ) ((RasterImageNode) m_svgCanvas.getUpdateManager().getBridgeContext().getGraphicsNode(m_imageNod e)).dispose(); m_svgCanvas.getUpdateManager().getBridgeContext().unbind(m_imageNode); 3.) I then add a static function that will invoke flush() on every BufferedImage object created by PNGRegistryEntry. At the end of this, I see my memory footprint go down to about 15 megs. Is there anything else that I can do here to free up more memory? In particular, there is a 5.5 meg int[] in memory that really bothers me. This seems to be an Offscreen Image that is referenced by the RepaintManager (javax.swing.RepaintManager). Is there a way to clear this without disabling doubleBuffering? thanks, -tomas --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
