You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Ugo Cei <u....@cbim.it> on 2004/02/11 15:39:38 UTC

Continuations and memory leaks

Dear friends,

I'm experiencing a memory leak in an application we are currently 
testing, which uses Flowscript and Woody. Since continuations store a 
reference to local variables, and the memory leak does not manifest 
itself if I don't create any continuation, I'm starting to suspect that 
my usage of form.showForm is causing the leak.

If this is indeed the case, how can I make sure that references to local 
variables will be properly nulled so that they can be garbage collected? 
Do they get forgotten when a continuation expires? And what if I 
invalidate the continuation?

	Ugo


Re: Continuations and memory leaks

Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> Do you have global variables in your scripts?

Not at all.

	Ugo


Re: Continuations and memory leaks

Posted by Christopher Oliver <re...@verizon.net>.
Do you have global variables in your scripts?

Ugo Cei wrote:

> Christopher Oliver wrote:
>
>> Ugo Cei wrote:
>>
>>> I'm experiencing a memory leak in an application we are currently 
>>> testing, which uses Flowscript and Woody. Since continuations store 
>>> a reference to local variables, and the memory leak does not 
>>> manifest itself if I don't create any continuation, I'm starting to 
>>> suspect that my usage of form.showForm is causing the leak.
>>>
>> What objects are leaked? Did you use Optimizeit or JProfiler to 
>> determine this? What does your script look like?
>
>
> All sorts of objects. My application uses Hibernate to persist objects 
> and retrieve them for editing in a Woody form. Those objects in turn 
> contain references to other persistent and/or transient objects or 
> collections of the same. Some of those references are really to 
> dynamic proxies, since Hibernate uses dynamic proxies for lazy loading.
>
> I am using Optimizeit and it shows lots of objects that are never 
> garbage-collected. The chains of references leading to these objects 
> are rather complex and make debugging the real case very difficult. I 
> will try to prepare a simpler testcase.
>
>>> If this is indeed the case, how can I make sure that references to 
>>> local variables will be properly nulled so that they can be garbage 
>>> collected? Do they get forgotten when a continuation expires? 
>>
>> Yes.
>>
>>> And what if I invalidate the continuation
>>
>> Yes.
>
>
> Hmmm, from my tests, it looks like doing:
>
> var k = form.showForm(...);
> k.invalidate();
>
> does not make any difference. But I seem to recall that showForm() 
> creates not one but *two* continuations, so maybe I need to invalidate 
> also the one that is not returned by the function, but how?
>
> I also waited about 10 minutes to see if the expiration of 
> continuations  could allow the GC to reclaim some objects, but this 
> did not seem to be the case too.
>
>     Thank you,
>
>         Ugo
>
>


Re: Continuations and memory leaks

Posted by Ugo Cei <u....@cbim.it>.
I did some tests with Woody and I can confirm that everything behaves as 
advertised. Local variables held by continuations become 
garbage-collectable when the continuation returned by showForm is 
invalidated and also when it expires.

(I still think I have a memory leak if I end the script with 
cocoon.redirectTo instead of cocoon.sendPage, but I cannot replicate 
this behaviour in a simple testcase, so I will need to investigate further).

Anyway, I think maybe it's worth pointing out that, if you cannot or 
don't want to invalidate your continuations, you risk holding on to lots 
of objects for a long time, since the default expiration time for 
continuations is 1 hour, if I'm not mistaken.

	Ugo


Re: Continuations and memory leaks

Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:

> Look at Optimizeit and see if there are any instances of 
> org.mozilla.javascript.cotinuations.Continuation or 
> org.apache.cocoon.components.flow.WebContinuation still around after this.

OK. This leaks a java.awt.Rectangle (plus a WebContinuation and a 
Continuation) each time sendPageAndWait is called:

function leakit() {
   var object = new Packages.java.awt.Rectangle();
   cocoon.sendPageAndWait("leakit.html");
   cocoon.sendPage("leakit.html");
}

But this does not:

function leakit() {
   var object = new Packages.java.awt.Rectangle();
   var k = cocoon.sendPageAndWait("leakit.html");
   k.invalidate();
   cocoon.sendPage("leakit.html");
}

So invalidating the continuations seems to be enough. Next I'll try to 
do the same with Woody's showForm.

	Ugo




Re: Continuations and memory leaks

Posted by Christopher Oliver <re...@verizon.net>.
Ugo Cei wrote:

> Christopher Oliver wrote:
>
>> Ugo Cei wrote:
>>
>>> I'm experiencing a memory leak in an application we are currently 
>>> testing, which uses Flowscript and Woody. Since continuations store 
>>> a reference to local variables, and the memory leak does not 
>>> manifest itself if I don't create any continuation, I'm starting to 
>>> suspect that my usage of form.showForm is causing the leak.
>>>
>> What objects are leaked? Did you use Optimizeit or JProfiler to 
>> determine this? What does your script look like?
>
>
> All sorts of objects. My application uses Hibernate to persist objects 
> and retrieve them for editing in a Woody form. Those objects in turn 
> contain references to other persistent and/or transient objects or 
> collections of the same. Some of those references are really to 
> dynamic proxies, since Hibernate uses dynamic proxies for lazy loading.
>
> I am using Optimizeit and it shows lots of objects that are never 
> garbage-collected. The chains of references leading to these objects 
> are rather complex and make debugging the real case very difficult. I 
> will try to prepare a simpler testcase.
>
If this is indeed the case, how can I make sure that references to local 
variables will be properly nulled so that they can be garbage collected? 
Do they get forgotten when a continuation expires?

>> Yes.
>>
>>> And what if I invalidate the continuation
>>
>> Yes.
>
>
> Hmmm, from my tests, it looks like doing:
>
> var k = form.showForm(...);
> k.invalidate();
>
> does not make any difference. But I seem to recall that showForm() 
> creates not one but *two* continuations, so maybe I need to invalidate 
> also the one that is not returned by the function, but how?
>
 From looking at woody2.js showForm() seems to return the first 
continuation it creates, so the above should release all the 
continuations created during showForm().

> I also waited about 10 minutes to see if the expiration of 
> continuations  could allow the GC to reclaim some objects, but this 
> did not seem to be the case too.
>
Look at Optimizeit and see if there are any instances of 
org.mozilla.javascript.cotinuations.Continuation or 
org.apache.cocoon.components.flow.WebContinuation still around after this.

Chris

Re: Continuations and memory leaks

Posted by Ugo Cei <u....@cbim.it>.
Christopher Oliver wrote:
> Ugo Cei wrote:
>> I'm experiencing a memory leak in an application we are currently 
>> testing, which uses Flowscript and Woody. Since continuations store a 
>> reference to local variables, and the memory leak does not manifest 
>> itself if I don't create any continuation, I'm starting to suspect 
>> that my usage of form.showForm is causing the leak.
>>
> What objects are leaked? Did you use Optimizeit or JProfiler to 
> determine this? What does your script look like?

All sorts of objects. My application uses Hibernate to persist objects 
and retrieve them for editing in a Woody form. Those objects in turn 
contain references to other persistent and/or transient objects or 
collections of the same. Some of those references are really to dynamic 
proxies, since Hibernate uses dynamic proxies for lazy loading.

I am using Optimizeit and it shows lots of objects that are never 
garbage-collected. The chains of references leading to these objects are 
rather complex and make debugging the real case very difficult. I will 
try to prepare a simpler testcase.

>> If this is indeed the case, how can I make sure that references to 
>> local variables will be properly nulled so that they can be garbage 
>> collected? Do they get forgotten when a continuation expires? 
> Yes.
>> And what if I invalidate the continuation
> Yes.

Hmmm, from my tests, it looks like doing:

var k = form.showForm(...);
k.invalidate();

does not make any difference. But I seem to recall that showForm() 
creates not one but *two* continuations, so maybe I need to invalidate 
also the one that is not returned by the function, but how?

I also waited about 10 minutes to see if the expiration of continuations 
  could allow the GC to reclaim some objects, but this did not seem to 
be the case too.

	Thank you,

		Ugo


Re: Continuations and memory leaks

Posted by Christopher Oliver <re...@verizon.net>.
Ugo Cei wrote:

> Dear friends,
>
> I'm experiencing a memory leak in an application we are currently 
> testing, which uses Flowscript and Woody. Since continuations store a 
> reference to local variables, and the memory leak does not manifest 
> itself if I don't create any continuation, I'm starting to suspect 
> that my usage of form.showForm is causing the leak.
>
What objects are leaked? Did you use Optimizeit or JProfiler to 
determine this? What does your script look like?

> If this is indeed the case, how can I make sure that references to 
> local variables will be properly nulled so that they can be garbage 
> collected? Do they get forgotten when a continuation expires? 

Yes.

> And what if I invalidate the continuation

Yes.

>
>
>     Ugo
>
>