我在使用Delphi记录时遇到了一个问题。这是我的问题代码:
function CrawlThread.CrawlLinks: bool;
var
Matches: TMatchCollection;
Match: TMatch;
i: integer;
begin
Matches:= TRegex.Matches(code, frmCrawler.Edit2.Text);
if Matches.Count > 0 then
begin
i:= 0;
for Match in Matches do
begin
SetLength(CrawledLinks, i + 1);
if (POS('https://', Match.Value) = 0) then
CrawledLinks[i]:= 'http://' + Match.Value
else
CrawledLinks[i]:= Match.Value;
inc(i);
end;
Result:= true;
end;
Matches:= TRegex.Matches(code, frmCrawler.Edit3.Text);
if Matches.Count > 0 then
begin
i:= 0;
for Match in Matches do
begin
SetLength(FollowLinks, i + 1);
if (POS('https://', Match.Value) = 0) then
FollowLinks[i]:= 'http://' + Match.Value
else
FollowLinks[i]:= Match.Value;
inc(i);
end;
Result:= true;
end;
这段代码在线程中被多次调用,如果我注释它,我的内存使用量就会达到26 up,而不是成长起来.当我使用它时,我启动了大约50 1MB (这不是一个问题),但它一直以每分钟1MB的速度增长(在1分钟内,这段代码被调用了数百次)。
使用ReportMemoryLeaksOnShutdown:= true;我得到以下输出:
在注释或使用代码时几乎是一样的,所以我不相信它在使用代码时每分钟解释1MB。当然,UnicodeString泄漏会困扰我,但由于我得到了它们,即使不使用代码,我也不认为它们是问题所在。你知道为什么这段代码占用了这么多内存吗?
发布于 2015-11-22 19:36:27
TStringList
中,而无需清理它。TStringList
。您是否尝试过搜索项目中的所有TStringList.Create
并确保有匹配的TStringList.Free
?同样适用于TCriticalSection
和TIdHashMessageDigest5
frmCrawler.Edit2.Text
和frmCrawler.Edit3.Text
的错误。https://stackoverflow.com/questions/33844495
复制相似问题