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 Peter Wagener <pe...@hypoluxo.com> on 2006/06/03 00:42:52 UTC
Cleaning up JSVGCanvas Memory
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: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Cleaning up JSVGCanvas Memory
Posted by th...@kodak.com.
Hi Peter,
Peter Wagener <pe...@hypoluxo.com> wrote on 06/02/2006 06:42:52
PM:
> 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.
Are you using 'trunk' of the svg11 branch.
> 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:
I think I've mentioned this before but I seriously question
the need to do all this.
> The updated nightly code, however, hits a NullPointerException when
> attempting to fire an event listener after removing a child node:
It looks like you are using trunk. This has come nice new
features (sXBL) and will be the future of Batik but svg11 is
currently more stable.
> java.lang.NullPointerException
> at org.apache.batik.dom.events.EventSupport.fireEventListeners
> (Unknown Source)
It's a little hard to see what is causing this, line numbers
would help. You can get line numbers by adding a file called
build.properties with the line "debug=on" next to the build.xml
file at the top of the batik build tree.
> 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?
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org