You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by bart remmerie <re...@gmail.com> on 2007/05/04 09:22:50 UTC

cforms showForm and memory leaks: quick question

Dear all,

I'm rewriting some of my cocoon-code and I have the following question that
continues to bother me.

I use flow to show a cform (see code below), and I'm wondering if

I need to "terminate" each function in flow in a "clean" way to avoid memory
leaks (after the form.showForm(...) provide some action (redirect the user)

or is it perfectly possible to terminate such a function with the
form.showForm("myform-display-pipeline.jx"); (where the user redirects
her/himself using simple hyperlinks) ?

Is there any info available on this topic ?


function showMyForm(){
   var form=new Form("forms/myform_model.xml");
   form.createBinding("forms/myform_bind_bean.xml");
   form.load(myBean);
   form.showForm("myform-display-pipeline.jx");
}

In the past, I used to have a couple of submit widgets which could be used
to "redirect" the user after completing the form (these were included after
the form.showForm line:

if (form.getWidget().getSubmitWidget().getName().equals("add_record")){
        cocoon.redirectTo("/addNewRecord/");
}//end if
else ...

Thanks
Bart

Re: cforms showForm and memory leaks: quick question

Posted by Jason Johnston <co...@lojjic.net>.
On Fri, 04 May 2007 22:33:31 +0200, Dev at weitling <de...@weitling.net> wrote:
> 
>>> I use flow to show a cform (see code below), and I'm wondering if
>>> I need to "terminate" each function in flow in a "clean" way to avoid
>>> memory leaks (after the form.showForm(...) provide some action
>>> (redirect the user)
>>
>> I think this is not necessary.  The form.showForm() call creates a
>> continuation, which keeps a handle on any objects in memory.  After a
>> given period (configured in the xconf) the continuation will be
>> automatically expired, at which point any objects it holds will be
>> garbage collected.  As long as all those objects are things you're
>> willing to have in memory for the lifetime of the continuation, you
>> can just leave it be.
> 
> Yesno. As far as I understood used Avalon components as well as some
> Java objects (e.g. those with that nice "dispose" method) should be put
> back or disposed before a continuation is created.


Yes Florian, that's certainly true.  Any objects that need to have a special cleanup method called (.dispose() for Avalon components, .close() for IO streams, etc.) need to have that method called *before* the continuation is suspended, since there's no guarantee it will ever be resumed.

I should also mention that if there are any objects stored as JS variables that you know you won't need anymore, and don't want to wait for the continuation to expire before they get garbage collected, you can set the variable to null to release the reference immediately:

   var obj = new InsanelyHeavyObject();
   cocoon.sendPageAndWait("pipeline", {obj:obj});
   obj = null; // releases reference, can be GC'd
   




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: cforms showForm and memory leaks: quick question

Posted by Dev at weitling <de...@weitling.net>.
>> I use flow to show a cform (see code below), and I'm wondering if
>> I need to "terminate" each function in flow in a "clean" way to avoid
>> memory leaks (after the form.showForm(...) provide some action
>> (redirect the user)
>
> I think this is not necessary.  The form.showForm() call creates a
> continuation, which keeps a handle on any objects in memory.  After a
> given period (configured in the xconf) the continuation will be
> automatically expired, at which point any objects it holds will be
> garbage collected.  As long as all those objects are things you're
> willing to have in memory for the lifetime of the continuation, you
> can just leave it be.

Yesno. As far as I understood used Avalon components as well as some
Java objects (e.g. those with that nice "dispose" method) should be put
back or disposed before a continuation is created.

Just my 2 cents.

Florian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: cforms showForm and memory leaks: quick question

Posted by Jason Johnston <co...@lojjic.net>.
bart remmerie wrote:
> Dear all,
> 
> I'm rewriting some of my cocoon-code and I have the following question 
> that continues to bother me.
> 
> I use flow to show a cform (see code below), and I'm wondering if
> 
> I need to "terminate" each function in flow in a "clean" way to avoid 
> memory leaks (after the form.showForm(...) provide some action (redirect 
> the user)

I think this is not necessary.  The form.showForm() call creates a 
continuation, which keeps a handle on any objects in memory.  After a 
given period (configured in the xconf) the continuation will be 
automatically expired, at which point any objects it holds will be 
garbage collected.  As long as all those objects are things you're 
willing to have in memory for the lifetime of the continuation, you can 
just leave it be.


> or is it perfectly possible to terminate such a function with the 
> form.showForm("myform-display-pipeline.jx"); (where the user redirects 
> her/himself using simple hyperlinks) ?
> 
> Is there any info available on this topic ?
> 
> 
> function showMyForm(){
>    var form=new Form("forms/myform_model.xml");
>    form.createBinding("forms/myform_bind_bean.xml");
>    form.load (myBean);
>    form.showForm("myform-display-pipeline.jx");
> }
> 
> In the past, I used to have a couple of submit widgets which could be 
> used to "redirect" the user after completing the form (these were 
> included after the form.showForm line:
> 
> if (form.getWidget().getSubmitWidget().getName().equals("add_record")){
>         cocoon.redirectTo("/addNewRecord/");
> }//end if
> else ...
> 
> Thanks
> Bart


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org