Solved

ADOQuery dont free up memory when freed

Posted on 2003-11-26
16
2,158 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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