Hi to all, I'm trying to investigate on a high memory usage, by an svg application I made. I've split the components into mini test cases, and I'm profiling each of them. What I find very strange is that a very simple svg application (described below) ranges from 30Mb to 186Mb, and what's worse, for a very long time (half the test time, 5h) the oscillations are very high. see the chart: http://img19.imageshack.us/my.php?image=pesosvg2he9.png
Is this the expected behaviour? the test case: It is basically the default SVGApplication from http://xmlgraphics.apache.org/batik/using/scripting/java.html it repeats forever -add a rect (first time only) -add an anim (translation of the rect) (first time only) -start the anim -wait for some time (1s) batik version is 1.7 the pc is running ubuntu 8.10, 64 bit, dual core, latest updates. netbeans ide & profiler http://img19.imageshack.us/my.php?image=pesosvg2he9.png package demo.test; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import org.apache.batik.dom.svg.SVGDOMImplementation; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.svg.SVGLoadEventDispatcherAdapter; import org.apache.batik.swing.svg.SVGLoadEventDispatcherEvent; import org.apache.batik.script.Window; import org.apache.batik.swing.svg.SVGUserAgentAdapter; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.events.EventTarget; import org.w3c.dom.svg.SVGAnimationElement; public class SimpleSvg { public static void main(String[] args) { new SimpleSvg(); } JFrame frame; JSVGCanvas canvas; Document document; Window window; private boolean loaded; class LocalSVGUserAgentHandler extends SVGUserAgentAdapter { @Override public void displayError(String message) { System.out.println("SVGError: " + message); } @Override public void displayError(Exception ex) { //System.out.println("SVGException: " + ex); ex.printStackTrace(); } } public SimpleSvg() { frame = new JFrame(); //canvas = new JSVGCanvas(); canvas = new JSVGCanvas(new LocalSVGUserAgentHandler(), true, true); // Forces the canvas to always be dynamic even if the current // document does not contain scripting or animation. canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); canvas.addSVGLoadEventDispatcherListener(new SVGLoadEventDispatcherAdapter() { public void svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) { // At this time the document is available... document = canvas.getSVGDocument(); // ...and the window object too. window = canvas.getUpdateManager(). getScriptingEnvironment().createWindow(); // Registers the listeners on the document // just before the SVGLoad event is // dispatched. registerListeners(); // It is time to pack the frame. frame.pack(); } }); frame.addWindowListener(new WindowAdapter() { public void windowOpened(WindowEvent e) { // The canvas is ready to load the base document // now, from the AWT thread. canvas.setURI(getClass().getResource("/img/testanim.svg").toString()); } }); frame.getContentPane().add(canvas); frame.setSize(800, 600); frame.show(); int cont = 0; //while (true && cont < 10) { while (true ) { try { Thread.sleep(50); if (loaded) { //when loaded, add rect, anim, start it addRect(); addAnim(); cont++; Thread.sleep(1000); //OR remove anim & rect //removeRectAnim(); //Logger.getAnonymousLogger().info(utils.MemAndThreadUsage.getMemoryUsage()); } } catch (InterruptedException ex) { Logger.getAnonymousLogger().log(Level.SEVERE, null, ex); } Logger.getAnonymousLogger().info("iter:"+cont); } //System.exit(0); } void removeRectAnim() throws InterruptedException { canvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(new Runnable() { public void run() { // Insert some actions on the DOM here String id = "anim1"; Element elt = document.getElementById(id); document.getElementById(id).getParentNode().removeChild(elt); id = "testrect2"; elt = document.getElementById(id); document.getElementById(id).getParentNode().removeChild(elt); } }); } void addAnim() throws InterruptedException { canvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(new Runnable() { public void run() { // Insert some actions on the DOM here Element anim = document.getElementById("anim1"); if (anim == null) { System.out.println("create new anim"); Element elt = document.getElementById("testrect2"); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; //creating animation anim = document.createElementNS(svgNS, "animateMotion"); String id = "anim1"; anim.setAttributeNS(null, "id", id); anim.setAttributeNS(null, "to", "-100,-100"); anim.setAttributeNS(null, "begin", "indefinite"); anim.setAttributeNS(null, "dur", "0.2s"); anim.setAttributeNS(null, "fill", "remove"); //adding anim elt.appendChild(anim); } boolean res = ((SVGAnimationElement) anim).beginElement(); System.out.println("anim started with res:" + res); } }); } void addRect() throws InterruptedException { canvas.getUpdateManager().getUpdateRunnableQueue().invokeAndWait(new Runnable() { public void run() { // Insert some actions on the DOM here Element rect = document.getElementById("testrect2"); if (rect == null) { System.out.println("create new rect"); Element g = document.getElementById("layer1"); String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI; rect = document.createElementNS(svgNS, "rect"); rect.setAttributeNS(null, "id", "testrect2"); rect.setAttributeNS(null, "x", "50"); rect.setAttributeNS(null, "y", "50"); rect.setAttributeNS(null, "width", "50"); rect.setAttributeNS(null, "height", "50"); g.appendChild(rect); } else { System.out.println("found rect"); } } }); } public void registerListeners() { // Gets an element from the loaded document. Element elt = document.getElementById("testrect"); EventTarget t = (EventTarget) elt; this.loaded = true; } } //################################################################## //svg test image <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:cc="http://creativecommons.org/ns#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" width="744.09448819" height="1052.3622047" id="svg2" sodipodi:version="0.32" inkscape:version="0.46" sodipodi:docname="testanim.svg" inkscape:output_extension="org.inkscape.output.svg.inkscape"> <defs id="defs4"> <inkscape:perspective sodipodi:type="inkscape:persp3d" inkscape:vp_x="0 : 526.18109 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="744.09448 : 526.18109 : 1" inkscape:persp3d-origin="372.04724 : 350.78739 : 1" id="perspective10" /> </defs> <sodipodi:namedview id="base" pagecolor="#ffffff" bordercolor="#666666" borderopacity="1.0" gridtolerance="10000" guidetolerance="10" objecttolerance="10" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="0.35" inkscape:cx="375" inkscape:cy="520" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="false" inkscape:window-width="762" inkscape:window-height="737" inkscape:window-x="141" inkscape:window-y="25" /> <metadata id="metadata7"> <rdf:RDF> <cc:Work rdf:about=""> <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> </cc:Work> </rdf:RDF> </metadata> <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1"> <rect style="opacity:1;fill:#fe8f00;fill-opacity:0.9;fill-rule:nonzero;stroke:#ffa400;stroke-width:1;stroke-linecap:round;stroke-linejoin:round;marker:none;marker-start:none;marker-mid:none;marker-end:none;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" id="testrect" width="245.71428" height="137.14285" x="80" y="175.21933" /> </g> </svg> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
