You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Antonio Gallardo <ag...@agsoftware.dnsalias.com> on 2003/12/08 07:47:25 UTC

[Flow] Question about return and cocoon.releaseComponent()

Hi:

Given the following snip of code:
-------------------------------------------------------------
function validateWoodyForm(form) {
var empId = parseInt(cocoon.request.emp_id);
var messageNoSelect = new String("Please select an Employee from the list");
....
try {
   factory = cocoon.getComponent(Packages.o.a.c.ojb...JdoPMF.ROLE);
   bean = handler.retrieve(empId, factory);

   if (bean instanceof Packages.test.Employee) {
      validateDataPerYear = employeeHandler.validateDataPerYear(bean);
   } else {
      form.getWidget("errorMessages").addMessage(messageNoSelect);
      return false;
    }
} finally {
   cocoon.releaseComponent(factory);
}
.... (more code in the function) ...
-------------------------------------------------------------

The snip is part of a function that validate Woody input. In this snip,
the function in the line:

*****   if (bean instanceof Packages.test.Employee) {

First verify we are able to got a correct bean, because the user can
"hack" the request and send back an EmpId that does not exist in the DB at
all (we already did this).

For this reasons, we use this line.

As you can note if the bean is not an instance of Packages.test.Employee,
then we fill an error message and return (wich cause the function to end).

My question is:

In this case the finally block is executed or not? As I understand if the
finally is not executed, then the factory will never be released and it
will mean a memory leak.

Please help.

Best Regards,

Antonio Gallardo




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


Re: [Flow] Question about return and cocoon.releaseComponent()

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Thanks for the aclaration.

Best Regards,

Antonio Gallardo

Frank Taffelt dijo:
>> My question is:
>>
>> In this case the finally block is executed or not? As I understand if
>> the
>> finally is not executed, then the factory will never be released and it
>> will mean a memory leak.
>
> this finally block gets every time evaluated when you leave your try
> block.
> Therefore the component is every time released.
>
> to verify this for yourself - place a print statement inside your block:
>
> <happyhackingmode>
> ...
> finally {
>    print("reaching finally block ...");
>    cocoon.releaseComponent(factory);
> }
> ...
> </happyhackingmode>
>
> Frank
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>


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


Re: [Flow] Question about return and cocoon.releaseComponent()

Posted by Frank Taffelt <fr...@interface-business.de>.
> My question is:
>
> In this case the finally block is executed or not? As I understand if the
> finally is not executed, then the factory will never be released and it
> will mean a memory leak.

this finally block gets every time evaluated when you leave your try block.
Therefore the component is every time released.

to verify this for yourself - place a print statement inside your block:

<happyhackingmode>
...
finally {
   print("reaching finally block ...");
   cocoon.releaseComponent(factory);
}
...
</happyhackingmode>

Frank


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