Solved

ADOQuery dont free up memory when freed

Posted on 2003-11-26
16
2,206 Views
Last Modified: 2010-04-03
HI

I Am working on a application which uses ADOQuery to access my
database. I Have to be able to create and then free the query when done, it
works ok except that the memory is not freed completely, and my application
eventualy dies.

This little code snippet demonstrates the problem, can anyone help me
find a solution.

For this test i simply created a form with a button when clicked excutes the following

I Use Delphi 7

  Coinitialize(nil);
  for i := 0 to 99 do
  Begin
    Query := TADOQuery.Create(nil);
    query.ConnectionString := ANY CONNECTION STRING;
    Query.SQL.Clear;
    Query.SQL.Insert(0,'SELECT * FROM table');
    Query.Open;
    Query.Close;
    Query.Free;
    Query := nil;
  End;
  Couninitialize;

Thanks

Erik



0
Comment
Question by:erik_aaskoven
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
  • +3
16 Comments
 

Accepted Solution

by:
lamtl354 earned 100 total points
ID: 9829450
your code seems use alot of memory every time you
 - create a new instance of ADOQuery,
 - open & close Database connection,
 - select with same query

if that was the case, i suggest
 - create ADOQuery once,
 - Open & close if really need.
 - use paramsbyname

hope helps
0
 

Author Comment

by:erik_aaskoven
ID: 9830125
Creating the Query once is not a possibility, because my application is multithreaded, I need to create when the thread starts and free when the thread ends.

The problem is that the Thead finishes OK, but memory is still allocated somewhere?

The above example is only to demonstrate the problem, not an actual function in my program.

Hope to get more suggestions

Erik
0
 

Assisted Solution

by:Cryonie
Cryonie earned 100 total points
ID: 9832471
Why don't you use query.Destroy ?

.Destroy free memory used by the object.


Manybe that would help ... :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:erik_aaskoven
ID: 9835811
Tried that, it does not work.  .free calls the objects destroy

But i have tried to just

Create and then free without adding sql, opening and closing, then there is no leak, it seems like the leak only appears when sql is inserted.
Only inserting SQL and not open and close the dataset still generates the same amount of memoryleaks
0
 

Expert Comment

by:Cryonie
ID: 9837388
And if you do a query.Clear before you destroy it?
0
 

Author Comment

by:erik_aaskoven
ID: 9837409
I expect you mean query.sql.clear??

In that case no difference
0
 
LVL 4

Assisted Solution

by:JeePeeTee
JeePeeTee earned 100 total points
ID: 9945857
Do you have the latest version of...

http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&DisplayLang=en

because....

When marshalling an ActiveX Data Objects (ADO) recordset between processes the handle count incrementally increases for each call made to the out-of- process component. This behavior only occurs if the rowset contains more than 8K of data.

regards
JeePee
0
 

Author Comment

by:erik_aaskoven
ID: 9947559
Yes i have the latest MDAC.

The memory leak occurs even when not opening and closing the query. And therefor also with very small dataset <8kb

I think the leak is comming from the query.SQL(something), but i dont know....

Erik
0
 
LVL 4

Expert Comment

by:JeePeeTee
ID: 9947765
The following modules are leaking at my place....

msado15.dll and w3mifxxx.dll (Pervasive SQL/2000). No leaking code in my project1.exe.

JeePee
0
 
LVL 4

Expert Comment

by:JeePeeTee
ID: 9947810
This is my current score....

Total Memory Leaks 19.900 1.275.200
   Nested Leak 19.900 1.275.200
   Nested leak 400 13.000 msado15.dll ! 0x000057EC
   Nested leak 100 1.400 msado15.dll ! 0x00008532
   Nested leak 400 240.000 W3BIF133.DLL ! 0x0000F019
   Nested leak 9.300 390.400 W3BIF133.DLL ! 0x00007AF0
   Nested leak 400 240.000 W3MIF137.DLL ! 0x00024941
   Nested leak 9.300 390.400 W3MIF137.DLL ! 0x0001C97E

1 digit is number of leaks encountered.... 2nd digit is the number of bytes lost... 3th part is the module and finally the entrypoint....
0
 
LVL 4

Assisted Solution

by:Delphian
Delphian earned 100 total points
ID: 10233337
Hi
I'm almost sure that the problem is
the OLE Db Provider. Actualize your
client connectivity from the Pervasive
producer.

I have this opinion because only the
ADO gateway library (msado15.dll)
and the Ole Db DLL (W3BIF133.DLL)
 are leaking. And our systems don't
leak here, but the difference is that
we use MS SQL Server here.

Update and/or reinstall the client tools
for Pervasive SQL.

[]s Fabricio
0
 
LVL 12

Assisted Solution

by:Ivanov_G
Ivanov_G earned 100 total points
ID: 10786463

  Here is the problem :

  Query := TADOQuery.Create(nil);
 
  try

  Query := TADOQuery.Create(Form1); // instead of Form1 - Self possible
0
 
LVL 4

Expert Comment

by:Delphian
ID: 10807512
Ivanov_G:
This is not the problem. The author freed the query
(called Query.Free) so the ownership is not the root
of the problem here.
See the code:
Query := TADOQuery.Create(nil);
.
.
.
.
Query.Close;
Query.Free;

Since he called Query.Free, the absence of
a owner is not a problem.


My thinking is that the pervasive SQL OLE DB driver is leaking,
based on the stats he showed.
0
 
LVL 4

Expert Comment

by:Delphian
ID: 11429343
Hi,
Please update the question.
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month3 days, 13 hours left to enroll

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question