0

我正在从文件列表框中加载文件。当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?
4

1 回答 1

2

List.clear 方法是否清理内存?

是的,TStringList.Clear方法释放由字符串分配的内存

stringlist 中的项目是否有数量限制?

不,没有实际限制。

你能告诉我如何解决吗?

不,因为不可能说代码

List.clear;
...
...// parse each word in memo1;
List.add(eachwordinmemo1);

泄漏与否。

于 2013-02-23T11:27:21.827 回答