Subject Re: [Firebird-Java] Memory Leek with Statement Pooling
Author Carsten Schäfer
Roman Rokytskyy wrote:
> Hi,
>
>> If i create a report with many different statements used memory is
>> growing. (Thats normal i thing, because the statements are cached)
>> After creating the report the connection is given back to the pool.
>> Memory is not given back.
>
> Correct. If I'm not wrong, this fix was added as you suggested to keep
> statements open even after connection.close(), because otherwise
> performance improvement is not so big.
>
>> And this happens every time i create the same report, so i think the
>> statement are not used again the the cache is growing and growing.
>
> When connection is released back to pool it is added to the end of
> the queue (e.g. we have LRU policy for connection caching). When you
> ask for a new connection, you get connection where no statements were
> prepared. In your case your memory will grow until all connections
> are used at least once (min is 5, max is 30).
>
>> If i setStatementPooling(false) and comment out the 4 lines after it
>> the memory is not growing, not for the first time i create the
>> report and not for creation after that.
>
> More or less correct. You release statement each time you close it.
>
>> I hope this can be fixed and is not a normal effect for statement
>> pooling, because i think the pooling really makes my application
>> faster.
>
> We need to add a pooling policy (LRU vs MRU). This is not 5 min.
> hack, I will add it to my todo list for 1.6. If I get time to fix it
> in 1.5.x, I will add it there too.
>

Pooling Policy is a good thing but it will only help if someone is creating
the same report two or more times in a row.
This is not very likely.
Is it right that the only case where statements can be reused after closing
a connection (giving back to pool) is when the same connection is used again
and with the same statements ?
It's not possibly to reuse staements with different connection, right ?
I made the suggustion to keep the statements open, thats right.
Is there an option to get the old behavior back (only reuse statement as
long as connection is not given back to pool) ?
Maybe thats easy to implement ?
Than i can do some more tests about perfomance and memory effects.

Another question:
Are the statements released ever ?
Can i do (call) something to release them ?

mfg
Carsten