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 Praveen Nayak2 <pr...@in.ibm.com> on 2009/11/04 11:26:55 UTC

Re: Canvas dispose

Hi Thomas,

Thanks! The test case helped!

Praveen




thomas.deweese@kodak.com 
28/10/2009 05:43 PM
Please respond to
batik-users@xmlgraphics.apache.org


To
batik-users@xmlgraphics.apache.org
cc
batik-users@xmlgraphics.apache.org
Subject
Re: Canvas dispose






Hi Praveen, 

Praveen Nayak2 <pr...@in.ibm.com> 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@kodak.com 
> 28/10/2009 04:12 PM 
> 
> Please respond to
> batik-users@xmlgraphics.apache.org 
> 
> To 
> 
> batik-users@xmlgraphics.apache.org 
> 
> cc 
> 
> batik-users@xmlgraphics.apache.org 
> 
> Subject 
> 
> Re: Canvas dispose 
> 
> 
> 
> 
> Hi Praveen, 
> 
> Praveen Nayak2 <pr...@in.ibm.com> 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.