xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Kane <dk...@money.buser.net>
Subject Multiplication of Event Handlers (May be related to JSVGCanvas - java.lang.OutOfMemoryError)
Date Tue, 04 Sep 2001 19:52:48 GMT
Folks,

We are also working on extending the JSVG canvas to give us some basic
animation capabilities.  We are triggering the update from a Javascript
event.  What is weird is that each time we reload the DOM, we seem to
double our Javascript event handlers.  The attached code illustrates the
problem.  The code will open the enclosed SVG document.  Everytime you
click the blue rectangle, it will write out a message to System.out and
then reloads the document.  The first time you click the rectangle, you
get one message.  The second time, two messages, the third time 4
messages, etc.

I wonder if this is related to Chris Kelly's note.  Our context is a
little different (we are triggering events from the SVG document itself,
and Chris is triggering events from an external button), but I wonder if a
proliferation of event handling objects (or something related) is the
source of the object leak?

I'm using Java 1.3.1, and I get the same results from both Batik 1.0 and
Batik 1.1RC1.

Any suggestions?

Sincerely,
David Kane

// What gets printed
entering down
After instance retrieved  <-- After clicking once
entering down
After instance retrieved
entering down
After instance retrieved  <-- After clicking twice
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved  <-- After clicking threee times
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved
entering down
After instance retrieved <-- After clicking four times.

// Example.java

import javax.swing.*;
import org.apache.batik.swing.*;
import org.apache.batik.swing.svg.*;
import org.w3c.dom.svg.*;

/**
 * This class is a driver used for exercising the JSVGAnimatedCanvas
 * component.
 */
public class Example {

	private static Example instance;
	private JSVGCanvas canvas;
	private SVGDocument document;

	public static Example getInstance()
	{
		return instance;
	}

    public static void main(String[] args) {

        	JFrame f = new JFrame("Batik");
        	Example app = new Example(f);
    }

    public Example(JFrame f) {
		instance = this;
        canvas = new JSVGCanvas();
        canvas.addSVGDocumentLoaderListener(new
MySVGDocumentLoaderAdapter());
        canvas.setURI("file:example.svg");
        f.getContentPane().add(canvas);
        f.setSize(200, 200);
        f.setVisible(true);
    }

	public void update()
	{
		  canvas.setSVGDocument(document);
	}

	class MySVGDocumentLoaderAdapter extends SVGDocumentLoaderAdapter
	{
	    public void documentLoadingCompleted(SVGDocumentLoaderEvent e)
	    {
		   	if (document == null)
					document = (e.getSVGDocument());
	    }
   }
}

// example.svg

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20001102//EN"
"http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd">
<svg id="example" xml:space="preserve">
      <rect id="test" x="5" y="5" width="35" height="20"
onclick="down(evt)" style="fill:blue;"/>
      <script type="text/ecmascript">
      function down(evt) {

     	  System.out.println("entering down");
    	  Packages.Example.getInstance().update();
    	  System.out.println("After instance retrieved");
   	  }
     </script>
</svg>

---------------------------------------------------------
 David Kane                     david_kane@houseofyin.com
"What's Life?"                  http://www.houseofyin.com
                                http://www.vraps.com


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


Mime
View raw message