Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADOQuery dont free up memory when freed

Posted on 2003-11-26
16
Medium Priority
?
2,274 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 400 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 400 total points
ID: 9832471
Why don't you use query.Destroy ?

.Destroy free memory used by the object.


Manybe that would help ... :)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 400 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 400 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 400 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

927 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