Subject Re: UDF or UDF calling process of Firebird may cause memory leaking
Author wenbin.pan
--- In firebird-support@yahoogroups.com, Helen Borrie <helebor@...> wrote:
>
> At 05:02 AM 30/11/2007, you wrote:
> >I am hit a memory leaking problem with Firebird UDF under Windows XP.
> >
> >Here is what I did:
> >
> >1. First create a stored procedure 'UDF_TEST' with just one UDF
> >function 'F_STRINGLENGTH'.
> >
> >SET TERM ^ ;
> >CREATE PROCEDURE UDF_TEST
> >AS
> >DECLARE VARIABLE STR_1 VARCHAR(20);
> >DECLARE VARIABLE POS_1 INTEGER;
> >DECLARE VARIABLE IDX INTEGER;
> >BEGIN
> >
> > STR_1 = '10-A-10';
> >
> > IDX = 0;
> > WHILE (IDX <= 20000) DO
> > BEGIN
> >
> > /* UDF function */
> > POS_1 = F_STRINGLENGTH(STR_1);
> >
> > IDX = IDX + 1;
> >
> > END
> >
> >END^
> >SET TERM ; ^
> >
> >2. Open the Windows Task Manager.
> >3. Execute the stored procedure, and watch the memory usage.
> >4. Run the stored procedure several times, the Firebird will raise the
> >following exception and the leaking memory has been released.
> >
> >*** IBPP::SQLException ***
> >Context: Statement::Execute( EXECUTE PROCEDURE MEM_TEST )
> >Message: isc_dsql_execute2 failed
> >
> >SQL Message : -902
> >Unsuccessful execution caused by a system error that precludes
> >successful execution of subsequent statements
> >
> >Engine Code : 335544721
> >Engine Message :
> >Unable to complete network request to host "localhost".
> >Error reading data from the connection.
> >
> >If I put the UDF function statement in the comment, and execute the
> >stored procedure. There would be no memory leaking problem.
> >
> >Then I execute the following UDF function statement 1000 times:
> >
> >SELECT F_STRINGLENGTH('10-A-10') FROM RDB$DATABASE;
> >
> >The memory usage is clearly growing up.
> >
> >Then I disconnect the database, those used memory was not released.
> >
> >This problem can reproduced on 2 desktops. I think both of the
> >desktops have the same environment:
> >
> >Operation System: Windows XP Pro
> >Firebird: Firebird 2.0.1 (Win32 Build)
> >UDF: 2007-02-09
> >
> >Anyone has any idea if I did something wrong. Or there is the way to
> >work around the problem. Your help is appreciated.
>
> You are not releasing memory after your calls to the string
function. Tell us
>
> 1. where you obtained this UDF (if you wrote it yourself, show the
code)
>
> 2. what your declaration of the UDF looks like.
>
> ./heLen
>

Hi,

I am using the FreeAdhocUDF which can be downloaded from
http://www.udf.adhoc-data.de/index_eng.html

We've tested the latest version. We found that after UDF calls, the
memory was not released until the connection to database is closed.