Solved

ADOQuery dont free up memory when freed

Posted on 2003-11-26
16
2,092 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
  • 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
 

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now