Hi All,

I've recently updated my application from using the released Batik 1.6 to a nightly build (from a week ago or so). Most things work well, and it cleared up one of my more annoying issues: previously having more than one JSVGCanvas instance would consistently render the document off-center... the nightly build apparently fixed that for me.

The only issue I'm having now is with cleaning up my JSVGCanvas instances when I want to release all the memory associated with them. Here is the code I was using with the 1.6 release; my custom extension of JSVGCanvas includes these methods:

<code>
    void destroyCanvas() {
        ToolTipManager ttipman = ToolTipManager.sharedInstance();
        ttipman.unregisterComponent(this);
        releaseRenderingReferences();

        stopProcessing();
        removeUpdateManager();

        removeAllNodes();
        removeAll();

        bridgeContext = null;
        listener = null;
        listenerList = null;
    }

    private void removeUpdateManager() {
        if (updateManager != null) {
            updateManager.getBridgeContext().dispose();
            updateManager = null;
        }
    }

    private void removeAllNodes() {

        SVGDocument document = getSVGDocument();
        if (document != null) {
            SVGSVGElement s = document.getRootElement();
            removeNodes(s);
        }

        System.gc();
    }

    private void removeNodes(Node n) {
        Node childNode;
        Node prevChildNode;

        for (childNode = n.getLastChild(); childNode != null;) {
            if (childNode.hasChildNodes()) {
                removeNodes(childNode);
            }
            prevChildNode = childNode.getPreviousSibling();
            if (!(childNode instanceof SVGOMPathElement)) {
                n.removeChild(childNode);
            }

            childNode = prevChildNode;
        }
    }
</code>


The updated nightly code, however, hits a NullPointerException when attempting to fire an event listener after removing a child node:

java.lang.NullPointerException
at org.apache.batik.dom.events.EventSupport.fireEventListeners (Unknown Source) at org.apache.batik.dom.events.EventSupport.fireEventListeners (Unknown Source) at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
        at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
at org.apache.batik.dom.AbstractParentNode.fireDOMNodeRemovedEvent (Unknown Source)
        at org.apache.batik.dom.AbstractParentNode.removeChild(Unknown Source)
at com.W7Optics.AppClient.LMSView.shelf.ShelfViewCanvas.removeNodes (ShelfViewCanvas.java:71) at com.W7Optics.AppClient.LMSView.shelf.ShelfViewCanvas.removeAllNodes (ShelfViewCanvas.java:55) at com.W7Optics.AppClient.LMSView.shelf.ShelfViewCanvas.destroyCanvas (ShelfViewCanvas.java:35)
        ....

Interestingly, this only happens with the second instance of JSVGCanvas -- the first instance appears to clean itself up just fine. Before I go hopping through the code myself, does anyone have any suggestions?


Many Thanks,

Peter

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

Reply via email to