我正在从文件列表框中加载文件。当filelistbox中的文件数较大时,程序提示“内存不足”。如何解决?
提前致谢。
[已编辑]
public
...
List: Tstringlist;
...
procedure TForm1.FormCreate(Sender: TObject);
begin
List:=tstringlist.create;
List.sorted:=true;
end;
procedure TForm1.processfile;
var
i:integer;
begin
if filelistbox1.Count =0 then exit;
for i:=0 to filelistbox1.count-1 do // 10000 files in filelistbox1
begin
memo1.clear;
memo1.lines.loadfromfile(DirectoryListBox1+'\'+
filelistbox1.Items.Strings[i]);
Addinlist;
List.savetofile(afile);
end;
end;
procedure TForm1.Addinlist;
var
w1: string;
p1: tperlregex;
begin
List.clear;
p1:=tperlregex.Create(nil) ;
p1.Subject:=memo1.text;
p1.regex:='\w+';
while p1.MatchAgain do
begin
w1:=p1.MatchedExpression;
List.add(w1);
end;
freeandnil(p1);
end;
Windows task manager memory displays: (approxomate number)
file number reaches 10, used memory 402M
file number reaches 100, used memory 402M
file number reaches 500, used memory 408M
file number reaches 1000, used memory 412M
file number reaches 1600, used memory 432M
file number reaches 2200, used memory 460M
file number reaches 3000, used memory 500M
file number reaches 5500, used memory 650M // prompts "Out of memory", form1 freez
这是在 Delphi 7 上。我的问题是:
Does List.clear method clean memory?
Is there number limit to the items in stringlist?
Can you please let me know how to solve it?