Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tstringlist memory leak?

978 views
Skip to first unread message

Michael

unread,
Mar 12, 2001, 7:17:34 PM3/12/01
to
hi

I am currently developing this application that heavily relies on
tstringlist. Allthough I free and nil this object it doesnt seem to free the
memory at all. I am using the freeandnil function for this. Any ideas? Is
there any better internal structures to store temporary data then
tstringlist?

Also, I found that the ado component have a big memory leak and causes a lot
of pagefaults. Is this something common? I am connectiong to an access
database using the ado component shipped with D5 enterprise.

Thanks for any comments,

Michael
--
Software engineer
glopro.com


Paul Nicholls

unread,
Mar 12, 2001, 7:45:53 PM3/12/01
to
Are you remembering to use the Clear method of the TStringList to clear all
the strings prior to FreeAndNil?
If not, I think all the strings would still be in memory...if I am wrong in
my assumtion then feel free to let me know :)

--
Paul Nicholls (Delphi 5)
"The plastic veneer of civilized man is easily melted in the heat of the
moment" - Paul Nicholls

Home Page: www.southcom.com.au/~phantom
< IF YOU WANT TO EARN MONEY WHILE YOU SURF ON THE NET GO HERE: >
< http://www.alladvantage.com/go.asp?refid=BEM-274 >


Craig Stuntz (TeamB)

unread,
Mar 12, 2001, 7:57:46 PM3/12/01
to

Michael wrote:
>
> I am currently developing this application that heavily relies on
> tstringlist. Allthough I free and nil this object it doesnt seem to free the
> memory at all.

How are you judging that the memory has not been released? If you're
using Task Manager, don't -- the numbers displayed there have little to
do with actual memory usage. If you're using MemProof or BoundsChecker,
those programs give you good numbers and tell you exactly what is
causing the leak. If you're using one of these, please tell us where
the resource was created.

> Is
> there any better internal structures to store temporary data then
> tstringlist?

TStringList is pretty good.



> Also, I found that the ado component have a big memory leak and causes a lot
> of pagefaults. Is this something common? I am connectiong to an access
> database using the ado component shipped with D5 enterprise.

You can repeat your question on
borland.public.delphi.database.adoexpress if you want, but bear in mind
what I said above about Task Manager. You can get MemProof for free
from:

http://www.automatedqa.com/downloads/memproof.asp

So first find out exactly what is causing the leak.

HTH,

-Craig

--
Craig Stuntz (TeamB) Vertex Systems Corporation
Senior Developer http://www.vertexsoftware.com

Delphi/InterBase weblog: http://delphi.weblogs.com

Craig Stuntz (TeamB)

unread,
Mar 12, 2001, 7:53:23 PM3/12/01
to

Paul Nicholls wrote:
>
> Are you remembering to use the Clear method of the TStringList to clear all
> the strings prior to FreeAndNil?
> If not, I think all the strings would still be in memory...if I am wrong in
> my assumtion then feel free to let me know :)

This is wrong. It's not necessary to use Clear. If you're storing
object references in the Objects property, however, you'll have to Free
them manually, if it's not done elsewhere.

Michael

unread,
Mar 12, 2001, 11:39:21 PM3/12/01
to
I have only been using taskmanagere so far. I know that the taskmanager is
not reliable and havent relied on that to come up with the error. Windows
reports "out of memory" when I have run my program for an hour or so.
Taskmanager says I have still about 100mb of physical memory left, or in
other words plenty. I will download this memoryproof and try it with that
and then will be able to know better and be able to give more accurate
information.

I use the addobject method to add strings into the tstringlist.

For example

type
PQue = ^AQue;
AQue = record
url: string;
host: string;
filename: string;
id: integer;
end;
..

var
urlInfo : PQue;
new(urlInfo)
urlinfo^.host := 'borland.com';
urlinfo^.url := 'www.borland.com';
urlinfo^.filename := 'default.asp';
urlInfo^.id := 1;
list.addobject("path",TObject())

this is looped through with different data. Now how can I delete this in a
correct way. Since at the moment I simply just freeandnil(list);

which doesnt work. Do I have to free the object too? And I think that is the
problem, but how I can do this?

Cheers
Michael

"Craig Stuntz (TeamB)" <cstuntz@no_spam.vertexsoftware.com> wrote in message
news:3AAD708A.10B937C6@no_spam.vertexsoftware.com...

Bruce Roberts

unread,
Mar 12, 2001, 11:52:35 PM3/12/01
to

"Michael" <skyr...@glopro.com> wrote in message
news:98k8gd$e9...@bornews.inprise.com...

> type
> PQue = ^AQue;
> AQue = record

> var


> urlInfo : PQue;
> new(urlInfo)
> urlinfo^.host := 'borland.com';
> urlinfo^.url := 'www.borland.com';
> urlinfo^.filename := 'default.asp';
> urlInfo^.id := 1;

> list.addobject("path",TObject())

I presume the above is a typo and actually reads
list.AddObject ('path', tObject (urlInfo));

>
> this is looped through with different data. Now how can I delete this in a
> correct way. Since at the moment I simply just freeandnil(list);
>
> which doesnt work. Do I have to free the object too? And I think that is
the
> problem, but how I can do this?

Yes, not releasing the records is a leak. Try something like

var i : integer;

for i := 0 to (list.Count - 1) do
Dispose (aQue (list.Objects [i]));
FreeAndNil (list);

Michael

unread,
Mar 13, 2001, 12:29:42 AM3/13/01
to
Thanks for that, I will give it a try. And yes it was a typo.
"Bruce Roberts" <b...@attcanada.net> wrote in message
news:98k962$kk...@bornews.inprise.com...

Marek Roszak

unread,
Mar 13, 2001, 9:37:58 AM3/13/01
to
> type
> PQue = ^AQue;
> AQue = record
> url: string;
> host: string;
> filename: string;
> id: integer;
> end;

Hi,

I encountered problems trying to use declarations like that.

Try this:

AQue = record
url: string[255];
host: string[255];
filename: string[255];
id: integer[255];
end;

or use PChar if string[255] is too small but you have to get and free memory
for the items separately.

Mark


G Allen Casteran

unread,
Apr 12, 2001, 1:42:40 AM4/12/01
to
Or you can call Finalize(Objects[I]) before calling Free
0 new messages