| View previous topic :: View next topic |
| Author |
Message |
Victor Hadianto Guest
|
Posted: Wed Feb 02, 2005 8:31 am Post subject: TADOQuery memory leak? |
|
|
Hi All,
Does anyone know about memory leak issue in TADOQuery? I've search in Google
and Google Groups and I found only very little info about this, although the
problem is spot on. SysString is not released after closing and freeing ADO
Query. I found one workaround from QualityCentral #8837 but there's another
that I couldn't fix. The code is very simple:
adoQuery := TADOQuery.Create(nil);
adoQuery.Connection := adoConnection;
adoQuery.Prepared := True;
adoQuery.SQL.Add('SELECT Title, Description ');
adoQuery.SQL.Add('FROM User WHERE Id = ' + IntToStr(Self.FUserId));
adoQuery.Open();
adoQuery.SQL.Clear();
adoQuery.Close();
adoQuery.Free();
On MemProof this will yield SysString not freed resources from deep inside
TCustomADODataSet. The last three entries on the stack is like this:
system.pas WStrFromPWCharLen
variants.pas VarFromWStr
adodb.pas TCustomADODataSet::InternalInitFieldDefs
If I put this snippet in an iteration the number of SysString unreleased
will go up. Does anyone know any workaround/resolution for this issue?
Thanks,
Victor
|
|
| Back to top |
|
 |
AlexB Guest
|
Posted: Thu Feb 03, 2005 4:10 am Post subject: Re: TADOQuery memory leak? |
|
|
Victor Hadianto wrote:
| Quote: | Does anyone know about memory leak issue in TADOQuery?
...
adoQuery := TADOQuery.Create(nil);
adoQuery.Connection := adoConnection;
adoQuery.Prepared := True;
adoQuery.SQL.Add('SELECT Title, Description ');
adoQuery.SQL.Add('FROM User WHERE Id = ' + IntToStr(Self.FUserId));
adoQuery.Open();
Swap 2 following lines (at first close then clear):
adoQuery.SQL.Clear();
adoQuery.Close();
adoQuery.Free();
On MemProof this will yield SysString not freed resources from deep inside
TCustomADODataSet.
|
Maybe leak exists only in destructor? Try create ADOQuery at start of
program, reuse the object for some (10 000 000?) queries and delete at
finish. In case if no other leaks occur during operation, you can
"disregard" this issue ... In any case please tell us about the results.
AlexB.
|
|
| Back to top |
|
 |
AlexB Guest
|
Posted: Thu Feb 03, 2005 4:47 am Post subject: Re: TADOQuery memory leak? |
|
|
AlexB wrote:
| Quote: | Victor Hadianto wrote:
Does anyone know about memory leak issue in TADOQuery?
...
Maybe leak exists only in destructor?
AlexB.
|
After some investigation I see:
TADOQuery = class(TCustomADODataSet)
....
constructor TCustomADODataSet.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCommand := TADOCommand.Create(Self);
...
destructor TADOQuery.Destroy;
begin
// Problem: destroy before delete of members
inherited Destroy;
FreeAndNil(FSQL);
end;
destructor TADOCommand.Destroy;
begin
// The same problem: destroy before delete of members
inherited Destroy;
Connection := nil;
FCommandObject := nil;
FreeAndNil(FParameters);
end;
See this discussion:
[url]http://groups.google.ru/groups?hl=ru&lr=&threadm=41ed54ce%241%40newsgroups.borland.com&rnum=6&prev=/groups%3Fas_q%3DTADOCommand%26as_ugroup%3D*borland*%26as_scoring%3Dd%26lr%3D%26num%3D20%26hl%3Dru[/url]
Possible workarounds:
- don't create TADOQuery and TADOCommand dynamically (use some static
instances), "ignore small leak" on terminating of application;
- patch adodb.pas ...
AlexB.
|
|
| Back to top |
|
 |
Victor Hadianto Guest
|
Posted: Thu Feb 03, 2005 10:50 pm Post subject: Re: TADOQuery memory leak? |
|
|
Alex,
| Quote: | See this discussion:
[url]http://groups.google.ru/groups?hl=ru&lr=&threadm=41ed54ce%241%40newsgroups.borland.com&rnum=6&prev=/groups%3Fas_q%3DTADOCommand%26as_ugroup%3D*borland*%26as_scoring%3Dd%26lr%3D%26num%3D20%26hl%3Dru[/url]
|
Thanks for the investigative work. I followed that thread earlier in the NG
archive (there's more to it) since it's recent and I found that even the
latest release from Borland doesn't fix the issue.
| Quote: | Possible workarounds:
- patch adodb.pas ...
|
How would I patch the source manually?
Regards,
Victor
|
|
| Back to top |
|
 |
AlexB Guest
|
Posted: Fri Feb 04, 2005 4:32 am Post subject: Re: TADOQuery memory leak? |
|
|
Victor Hadianto wrote:
| Quote: | - patch adodb.pas ...
How would I patch the source manually?
|
Create a new empty project.
Copy adodb.pas into project directory and add to project.
Patch unit, build prj.
Copy patched 'pas' and new 'dcu' files into respective Delphi directories.
AlexB.
|
|
| Back to top |
|
 |
Pierre Roux Guest
|
Posted: Thu Feb 17, 2005 5:15 pm Post subject: Re: TADOQuery memory leak? |
|
|
I have the same problem and attempted to patch as suggested. However the
problem still remains.
Any other ideas?
"AlexB" <b.a.v (AT) inbox (DOT) ru> wrote
| Quote: | Victor Hadianto wrote:
- patch adodb.pas ...
How would I patch the source manually?
Create a new empty project.
Copy adodb.pas into project directory and add to project.
Patch unit, build prj.
Copy patched 'pas' and new 'dcu' files into respective Delphi directories.
AlexB.
|
|
|
| Back to top |
|
 |
Rich Guest
|
Posted: Mon Feb 21, 2005 6:06 pm Post subject: Re: TADOQuery memory leak? |
|
|
Have you seen this thread? I posted some comments
a week or so ago.
http://tinyurl.com/54oke
Rich
"Pierre Roux" <pierre (AT) infofx (DOT) co.za> wrote:
| Quote: | I have the same problem and attempted to patch as suggested. However the
problem still remains.
Any other ideas?
"AlexB" <b.a.v (AT) inbox (DOT) ru> wrote in message
news:4202fac2 (AT) newsgroups (DOT) borland.com...
Victor Hadianto wrote:
- patch adodb.pas ...
How would I patch the source manually?
Create a new empty project.
Copy adodb.pas into project directory and add to project.
Patch unit, build prj.
Copy patched 'pas' and new 'dcu' files into respective Delphi directories.
AlexB.
|
|
|
| Back to top |
|
 |
|