Print Thread
Memory leak when TOracleConnection.StatementCache=true
#65398 02/15/24 02:50 PM
Joined: Feb 2024
Posts: 3
Member
OP Offline
Member
Joined: Feb 2024
Posts: 3
Hi,
I'm the maintener of some Delphi 7 / 10 Windows services using our DOA components.
They poll the DB with many similar queries, so our dba asks me if is possible to cache the queries these services do.
Ok. I set to true the StatementCache property of the TOracleSession component.
The query appears to be effectively cached to Oracle but since then, I noticed a constant memory leak (proportional to the queries executed).
I have attached to this post a simple test app to reproduce the issue.
This app extracts the first rows (1..10) of a table. The query is repeated many times, so the memory leak is very evident.
Code
// Create a simple parametric query with 10 variants - StatementCacheSize of the session is 20
 // QUERY THE FIRST COLUMNS OF THE SPECIFIED TABLE OF THE DB
 MyQuery          := TOracleQuery.Create(nil);
 myQuery.Session  := OracleSession1;
 MyQuery.SQL.Text := 'SELECT * FROM '+myTableEdit.Text +' WHERE ROWNUM < ( :NUM + '+ IntToStr(random(10))+')' ;

 // Execute the query
 myQuery.DeclareAndSet('NUM',otString,IntToStr(random(100)));
 myQuery.Execute;
 myQuery.RowCount;
 myQuery.Close;
 FreeAndNIL(myQuery);
I have also played with many configurations but without success.
The only workaround seems to close and open periodically the session (logOff/logOn).
I also tried to download the latest releases of the DOA (trial version) but this seems not to fix my problem because the leak will persist.
We surely upgraded the components with the newer available but if the problem persists is obviously useless.
There are someone that faced and solved the same issues ?

Thanks,
Giovanni

Attached Files
CacheTest.zip (4.62 KB, 1 downloads)
SHA1: 358a7e3badb00e990d5e883174a1c94fe6649325
Re: Memory leak when TOracleConnection.StatementCache=true
gc@siospa.it #65400 02/16/24 09:49 AM
Joined: Aug 1999
Posts: 22,208
Member
Offline
Member
Joined: Aug 1999
Posts: 22,208
If logOff/logOn "fixes" the issue, then this would suggest that some session or query resources are not freed, either by the application, by the Direct Oracle Access components, or by the Oracle Client library functions. Can you let me know Oracle Client and Server version so that we can try to reproduce?


Marco Kalter
Allround Automations
Re: Memory leak when TOracleConnection.StatementCache=true
gc@siospa.it #65401 02/16/24 01:02 PM
Joined: Feb 2024
Posts: 3
Member
OP Offline
Member
Joined: Feb 2024
Posts: 3
We use 2 instances of oracle: 11 and 19

For Oracle 11:
SERVER VERSION : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
CLIENT VERSION : 11.2.0.1.0 Production

For Oracle 19:
SERVER VERSION : Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production (linux)
CLIENT VERSION : Version 19.10.0.0.0

To reproduce import and compile the zipped delphi project attached to the previous post, insert db/usr/pwd and a table to query, let's run it.
PS: the project has a 'typo' - please blank the 'Output Directory'

[Linked Image from i.imgur.com]

Thank you very much in advance.

Last edited by gc@siospa.it; 02/16/24 01:06 PM.
Re: Memory leak when TOracleConnection.StatementCache=true
gc@siospa.it #65402 02/16/24 01:18 PM
Joined: Feb 2024
Posts: 3
Member
OP Offline
Member
Joined: Feb 2024
Posts: 3
Another strange behavior of the component is that doesn't leak if the CacheSize property of the session is below the number of different queries to execute.
For example, if the application periodically does 10 different queries and the CacheSize is set to 9 there is no memory spill.
But this configuration is useless because the queries are periodically re-parsed again by the database.

Last edited by gc@siospa.it; 02/16/24 01:19 PM.

Moderated by  support 

Link Copied to Clipboard
Powered by UBB.threads™ PHP Forum Software 7.7.4
(Release build 20200307)
Responsive Width:

PHP: 7.1.33 Page Time: 0.066s Queries: 16 (0.028s) Memory: 2.5129 MB (Peak: 3.0378 MB) Data Comp: Off Server Time: 2024-05-05 21:42:13 UTC
Valid HTML 5 and Valid CSS