我在处理每个文件的时候 已经释放了啊,怎么到第22个文件的时候就内存溢出了啊,每个单独做都没问题,前面21个文件总和差不多将近600M,总计差不多400个文件,部分代码如下  List := TStringList.Create;  ///逐个文件进行统计
  for j := 0 to 400 do   //400个文件
  begin
    bString := SplitString(distList.Strings[j],'|');   ///分割行
    strDist := bString[1];              ///取省市名
    strCode := bString[0];              ///取pcode    try      ///程序运行的状态条
      ImpPanel.Visible := True;
      ImpPanel.Caption := '正在处理文件 ' + 'addr_'+strCode+'_out.txt' + ' 请稍候!!!';
      ImpPanel.Repaint;      List.LoadFromFile(Cur_Path+'\addr_bz_out\'+'addr_'+strCode+'_out.txt'); ///载入要取省市的数据      ///初始化变量
      Str1 := '';
      Str2 := '';
      countBI_all := 0;
      countUNIQ_all := 0;
      countBI_equal := 0;
      countUNIQ_equal := 0;
      countBI_unequal := 0;
      countUNIQ_unequal := 0;
      countSUM := List.Count;      ///逐条数据进行取出统计
      for i := 0 to List.Count - 1  do
      begin
        aString := SplitString(List.Strings[i],'|');
        Str1 := aString[0];
        Str2 := aString[3];        if copy(Str1,1,2)='@@' then
        begin
          countBI_all := countBI_all+1;
          if Str2='一致' then
            countBI_equal := countBI_equal+1
          else
            countBI_unequal := countBI_unequal+1;
        end ;      end;
      Sleep(100);  ///为了更清楚看到执行的过程,可以省略此处
      ImpPanel.Visible := false;
    
      finally
        List.Clear;
        List.Free;
      end;
    
    end;

解决方案 »

  1.   

    List.Clear; 移动到
    for   j   :=   0   to   400   do       //400个文件 
        begin 
    下。
      

  2.   

        List   :=   TStringList.Create; 
        try
        ///逐个文件进行统计 
        for   j   :=   0   to   400   do       //400个文件 
        begin 
            bString   :=   SplitString(distList.Strings[j], '| ');       ///分割行 
            strDist   :=   bString[1];                             ///取省市名 
            strCode   :=   bString[0];                             ///取pcode          
                ///程序运行的状态条 
                ImpPanel.Visible   :=   True; 
                ImpPanel.Caption   :=   '正在处理文件   '   +   'addr_ '+strCode+ '_out.txt '   +   '   请稍候!!! '; 
                ImpPanel.Repaint;             List.LoadFromFile(Cur_Path+ '\addr_bz_out\ '+ 'addr_ '+strCode+ '_out.txt ');   ///载入要取省市的数据             ///初始化变量 
                Str1   :=   ' '; 
                Str2   :=   ' '; 
                countBI_all   :=   0; 
                countUNIQ_all   :=   0; 
                countBI_equal   :=   0; 
                countUNIQ_equal   :=   0; 
                countBI_unequal   :=   0; 
                countUNIQ_unequal   :=   0; 
                countSUM   :=   List.Count;             ///逐条数据进行取出统计 
                for   i   :=   0   to   List.Count   -   1     do 
                begin 
                    aString   :=   SplitString(List.Strings[i], '| '); 
                    Str1   :=   aString[0]; 
                    Str2   :=   aString[3];                 if   copy(Str1,1,2)= '@@ '   then 
                    begin 
                        countBI_all   :=   countBI_all+1; 
                        if   Str2= '一致 '   then 
                            countBI_equal   :=   countBI_equal+1 
                        else 
                            countBI_unequal   :=   countBI_unequal+1; 
                    end   ;             end; 
                Sleep(100);     ///为了更清楚看到执行的过程,可以省略此处 
                ImpPanel.Visible   :=   false;                 
            end;
        finally
          List.Free; 
        end;
      

  3.   

    你不能在循环体内执行List.Free, 放到循环结束之后再执行。
      

  4.   

    不是TStringList的问题,LoadFromFile是会清除上次内存的,用FastMM检查一下是否有内存泄露。
      

  5.   

    第一个循环结束时,List就被你释放了,下一次再用时肯定有问题……