首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

out of Memory解决办法

2012-03-08 
out of Memory有没有国庆的时候同LZ一样在悲催加班的大虾,能不能帮我看下一下程序:在TMyThread中把文本文

out of Memory
有没有国庆的时候同LZ一样在悲催加班的大虾,能不能帮我看下一下程序:在TMyThread中把文本文件通过StringList在StringGrid中显示。当文本文件有600000行的时候,在导入到40%左右的时候就提示:Projece ss.exe raised exception class EOutOfMemory with message 'Out of memory'。大虾们能不能帮我看下是什么原因。


procedure TMyThread.Execute;
var
tmpList:TStringList;
  index,row:Integer;
  originalrow:integer;
  repeatcount:integer;
begin
FreeOnTerminate := True; {这可以让线程执行完毕后随即释放}
 if NewMsgBox.OpenDialog1.Execute then//选择文本文件
  begin
  tmpList:=TStringList.Create;//初始化StringList
  tmpList.LoadFromFile(NewMsgBox.OpenDialog1.FileName);//导入文本文件到StringList
  if tmpList.Count=0 then //文本文件为空 则退出
  begin
  exit;
  end
  else
  begin
  row:=NewMsgBox.PhoneGrid.RowCount;
  NewMsgBox.PhoneGrid.RowCount:=NewMsgBox.PhoneGrid.RowCount+tmpList.Count;
  for index:=0 to tmpList.Count-1 do //把TstringList的内容写入PhoneGrid PhoneGrid为StringGrid
  begin
  NewMsgBox.PhoneGrid.Cells[0,row]:=tmpList[index];
  row:=row+1;
  waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1;
  end;
  end;
  tmpList.Free;

  end;


end;

[解决办法]
哦,看错了

要不要真的全部加载到stringgrid?
用户滚动stringgrid时,实时从stringlist取出来填充stringgrid当前可见的行就行了吧

另外,下面这个没有progressmessages,可能没效果的:
waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1;
[解决办法]
你这个一股脑的把所有东西通通塞入内存,肯定会有问题啊,建议考虑分段显示,即一次显示多少条记录

热点排行