|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Canvas disposeHi, I use JSVGCanvas in an applet to show SVG diagrams. When the page is navigating away from the current page, I disposed the canvas in the applet stop method. I earlier had: canvas.dispose(); I have many pages each with an applet in it, with the SVG diagram, and users can switch between these pages, sometimes quite rapidly. I noticed there was memory leaking away. I then included a call to stopProcessing, which improved things. So I now have canvas.dispose(); canvas.stopProcessing(); 1. Is this sufficient? Also, at times during navigation, I see errors such as these logged in the console (I believe if I navigate away before the SVG is rendered): java.lang.NullPointerException at org.apache.batik.dom.events.EventListenerList.removeListener(Unknown Source) at org.apache.batik.dom.events.EventSupport.removeEventListenerNS(Unknown Source) at org.apache.batik.dom.AbstractNode.removeEventListenerNS(Unknown Source) at org.apache.batik.bridge.FocusManager.removeEventListeners(Unknown Source) at org.apache.batik.bridge.FocusManager.dispose(Unknown Source) ... (or a null pointer exception at setGraphicsNode) Can these add to a leak, and can I handle these somehow? Thanks, Praveen |
|||||||||||
|
|
Re: Canvas disposeHi Praveen,
Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 02:46:10 AM: > I have many pages each with an applet in it, with the SVG diagram, > and users can switch between these pages, sometimes quite rapidly. I > noticed there was memory leaking away. I then included a call to > stopProcessing, which improved things. So I now have > canvas.dispose(); > canvas.stopProcessing(); I don't think this is a good sequence. I would stop at canvas.dispose(). The call to 'stopProcessing()' is actually likely acting to prevent the action of canvas.dispose(). I've seen Swing hold onto the canvas much longer than desirable because it was the 'focus' component when it was not replaced by a new focus component. So you might try removing the canvas from the applet and adding a JButton in it's place. > 1. Is this sufficient? > > Also, at times during navigation, I see errors such as these logged > in the console (I believe if I navigate away before the SVG is rendered): > java.lang.NullPointerException These may be caused by your calling stopProcessing. |
|||||||||||
|
|
Re: Canvas disposeHi Thomas, Sorry for the wrong ordering below, my bad. The call is actually canvas.stopProcessing(); canvas.dispose(); I hope that order is alright. I also have code removing the canvas from the applet: this.getContentPane().remove(canvas); canvas = null; Any idea on console errors in the above scenario? Appreciate your help. Thanks, Praveen
Hi Praveen, Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 02:46:10 AM: > I have many pages each with an applet in it, with the SVG diagram, > and users can switch between these pages, sometimes quite rapidly. I > noticed there was memory leaking away. I then included a call to > stopProcessing, which improved things. So I now have > canvas.dispose(); > canvas.stopProcessing(); I don't think this is a good sequence. I would stop at canvas.dispose(). The call to 'stopProcessing()' is actually likely acting to prevent the action of canvas.dispose(). I've seen Swing hold onto the canvas much longer than desirable because it was the 'focus' component when it was not replaced by a new focus component. So you might try removing the canvas from the applet and adding a JButton in it's place. > 1. Is this sufficient? > > Also, at times during navigation, I see errors such as these logged > in the console (I believe if I navigate away before the SVG is rendered): > java.lang.NullPointerException These may be caused by your calling stopProcessing. |
|||||||||||
|
|
Re: Canvas disposeHi Praveen,
Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 07:39:39 AM: > Sorry for the wrong ordering below, my bad. The call is actually > canvas.stopProcessing(); > canvas.dispose(); Internally canvas.dispose ends up calling 'stopProcessing()' so your early call is only likely to cause problems. I strongly recommend that you remove it. > I also have code removing the canvas from the applet: > this.getContentPane().remove(canvas); > canvas = null; In my experience simply removing the canvas from the Swing hierarchy is not enough. You need to give it something else to 'point at'. You can take a look at test-sources/org/apachage/batik/swing/JSVGMemoryLeakTest.doSomething to see the sequence I have used in the past to 'help' the canvas go to GC. > Any idea on console errors in the above scenario? Appreciate your help. I suspect the problem is the extra call to stopProcessing. That method is async and I think you end up calling dispose on the BridgeContext twice in two separate threads - which isn't good. I don't think it will lead to memory leaks as one of the threads will likely run to completion, and in any case I'm confident that everything will go to GC if the canvas goes to GC (which I suspect it isn't currently). > thomas.deweese@... > 28/10/2009 04:12 PM > > Please respond to > batik-users@... > > To > > batik-users@... > > cc > > batik-users@... > > Subject > > Re: Canvas dispose > > > > > Hi Praveen, > > Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 02:46:10 AM: > > > I have many pages each with an applet in it, with the SVG diagram, > > and users can switch between these pages, sometimes quite rapidly. I > > noticed there was memory leaking away. I then included a call to > > stopProcessing, which improved things. So I now have > > canvas.dispose(); > > canvas.stopProcessing(); > > I don't think this is a good sequence. I would stop at > canvas.dispose(). The call to 'stopProcessing()' is actually > likely acting to prevent the action of canvas.dispose(). > > I've seen Swing hold onto the canvas much longer than > desirable because it was the 'focus' component when it was > not replaced by a new focus component. So you might try > removing the canvas from the applet and adding a JButton in > it's place. > > > 1. Is this sufficient? > > > > Also, at times during navigation, I see errors such as these logged > > in the console (I believe if I navigate away before the SVG is rendered): > > java.lang.NullPointerException > > These may be caused by your calling stopProcessing. |
|||||||||||
|
|
Re: Canvas disposeHi Thomas, Thanks! The test case helped! Praveen
Hi Praveen, Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 07:39:39 AM: > Sorry for the wrong ordering below, my bad. The call is actually > canvas.stopProcessing(); > canvas.dispose(); Internally canvas.dispose ends up calling 'stopProcessing()' so your early call is only likely to cause problems. I strongly recommend that you remove it. > I also have code removing the canvas from the applet: > this.getContentPane().remove(canvas); > canvas = null; In my experience simply removing the canvas from the Swing hierarchy is not enough. You need to give it something else to 'point at'. You can take a look at test-sources/org/apachage/batik/swing/JSVGMemoryLeakTest.doSomething to see the sequence I have used in the past to 'help' the canvas go to GC. > Any idea on console errors in the above scenario? Appreciate your help. I suspect the problem is the extra call to stopProcessing. That method is async and I think you end up calling dispose on the BridgeContext twice in two separate threads - which isn't good. I don't think it will lead to memory leaks as one of the threads will likely run to completion, and in any case I'm confident that everything will go to GC if the canvas goes to GC (which I suspect it isn't currently). > thomas.deweese@... > 28/10/2009 04:12 PM > > Please respond to > batik-users@... > > To > > batik-users@... > > cc > > batik-users@... > > Subject > > Re: Canvas dispose > > > > > Hi Praveen, > > Praveen Nayak2 <prnayak2@...> wrote on 10/28/2009 02:46:10 AM: > > > I have many pages each with an applet in it, with the SVG diagram, > > and users can switch between these pages, sometimes quite rapidly. I > > noticed there was memory leaking away. I then included a call to > > stopProcessing, which improved things. So I now have > > canvas.dispose(); > > canvas.stopProcessing(); > > I don't think this is a good sequence. I would stop at > canvas.dispose(). The call to 'stopProcessing()' is actually > likely acting to prevent the action of canvas.dispose(). > > I've seen Swing hold onto the canvas much longer than > desirable because it was the 'focus' component when it was > not replaced by a new focus component. So you might try > removing the canvas from the applet and adding a JButton in > it's place. > > > 1. Is this sufficient? > > > > Also, at times during navigation, I see errors such as these logged > > in the console (I believe if I navigate away before the SVG is rendered): > > java.lang.NullPointerException > > These may be caused by your calling stopProcessing. |
| Free embeddable forum powered by Nabble | Forum Help |