OK, just speculating here ... <G>
I'd think that "known problem with some string operations (especially concatenation) in a loop" means "writeln(os1+' '+os2+os3+os4+os5+os6)" is the problem, since this is string concatenation and is within a "while" loop ...
Joe.
-----Original Message----- From: Preben Mikael Bohn [SMTP:preben_bohn@yahoo.com] Sent: Tuesday, April 09, 2002 6:06 PM To: gpc@gnu.de Subject: Re: Memory leak in stringutils.pas?
I don't know if I understand you the right way (I probably don't). I just tried to move tokenize+dispose into a subroutine (but still in the loop) like the following, but it still has a memory leak...
program test1;
uses GPC, stringutils;
function split( var inStr : string; var os1,os2,os3,os4,os5,os6 : string; var c : charset ) : integer; var tokens : PPStrings; begin tokens := TokenizeString (inStr, c); os1 := tokens^[1]^; os2 := tokens^[2]^; os3 := tokens^[3]^; os4 := tokens^[4]^; os5 := tokens^[5]^; os6 := tokens^[6]^; split := tokens^.count; DisposePPStrings (tokens); end;
var line,os1,os2,os3,os4,os5,os6 : string; lineNumber, count : integer; c : charset;
begin c := ['¤']; lineNumber := 0; while lineNumber < 1000000 do begin line := 'string1¤string2¤string3¤string4¤string5¤string6'; inc(lineNumber); count := split(line, os1,os2,os3,os4,os5,os6,c); if (linenumber mod 10) = 0 then begin writeln('Line number : ', lineNumber); writeln(os1+' '+os2+os3+os4+os5+os6); end; end; end.
Best regards
Preben Bohn
--- Frank Heckenbach frank@g-n-u.de wrote: > =?iso-8859-1?q?Preben=20Mikael=20Bohn?= wrote:
After sucessfully installing GPC I tried the following
(basically a
loop around the stringutils test-program). However it seems to
have
a memoryleak, after a while (~14%MEM on my machine) it comes
out
with a segmentation fault (and with top you can see that the
memory
usage grows)...
The memory leak is not in the unit, but in GPC itself. It's a known problem with some string operations (especially concatenation) in a loop. (If you can read /proc/n/maps, you'll see that it's the stack, not the heap that grows.) Moving the thing out of the loop (syntactically, e.g. in a subroutine) is a work-around.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html
=====
Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com
Sorry! :-) Of course... I simply just have to learn to read... :) I was so hooked up on the idea that it was the tokenize/dispose-thing I did wrong...
It works great now, thank you!
Best regards
Preben Bohn
--- "da Silva, Joe" Joe.daSilva@emailmetering.com wrote: > OK, just speculating here ... <G>
I'd think that "known problem with some string operations (especially concatenation) in a loop" means "writeln(os1+' '+os2+os3+os4+os5+os6)" is the problem, since this is string concatenation and is within a "while" loop ...
Joe.
-----Original Message----- From: Preben Mikael Bohn [SMTP:preben_bohn@yahoo.com] Sent: Tuesday, April 09, 2002 6:06 PM To: gpc@gnu.de Subject: Re: Memory leak in stringutils.pas?
I don't know if I understand you the right way (I probably
don't).
I just tried to move tokenize+dispose into a subroutine (but
still
in the loop) like the following, but it still has a memory
leak...
program test1;
uses GPC, stringutils;
function split( var inStr : string; var os1,os2,os3,os4,os5,os6 : string; var c : charset ) : integer; var tokens : PPStrings; begin tokens := TokenizeString (inStr, c); os1 := tokens^[1]^; os2 := tokens^[2]^; os3 := tokens^[3]^; os4 := tokens^[4]^; os5 := tokens^[5]^; os6 := tokens^[6]^; split := tokens^.count; DisposePPStrings (tokens); end;
var line,os1,os2,os3,os4,os5,os6 : string; lineNumber, count : integer; c : charset;
begin c := ['¤']; lineNumber := 0; while lineNumber < 1000000 do begin line := 'string1¤string2¤string3¤string4¤string5¤string6'; inc(lineNumber); count := split(line, os1,os2,os3,os4,os5,os6,c); if (linenumber mod 10) = 0 then begin writeln('Line number : ', lineNumber); writeln(os1+' '+os2+os3+os4+os5+os6); end; end; end.
Best regards
Preben Bohn
--- Frank Heckenbach frank@g-n-u.de wrote: > =?iso-8859-1?q?Preben=20Mikael=20Bohn?= wrote:
After sucessfully installing GPC I tried the following
(basically a
loop around the stringutils test-program). However it seems
to
have
a memoryleak, after a while (~14%MEM on my machine) it
comes
out
with a segmentation fault (and with top you can see that
the
memory
usage grows)...
The memory leak is not in the unit, but in GPC itself. It's a known problem with some string operations (especially
concatenation) in
a loop. (If you can read /proc/n/maps, you'll see that it's the stack, not the heap that grows.) Moving the thing out of the loop (syntactically, e.g. in a subroutine) is a work-around.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/,
7977168E
GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html
=====
Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com
=====
__________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com
da Silva, Joe wrote:
OK, just speculating here ... <G>
I'd think that "known problem with some string operations (especially concatenation) in a loop" means "writeln(os1+' '+os2+os3+os4+os5+os6)" is the problem, since this is string concatenation and is within a "while" loop ...
Yes, that's what I meant. Of course, in this particular example, you could just replace `+' by `,' since WriteLn accepts any number of arguments. In other cases this might not be possible, then you might have to move the statements containing the concatenation.
Frank