关于delphi的内存泄露
为什么这个过程.运行一段时候后,虚拟内存(红框处)就彪到3个G,然后就outofmemory.试过去掉ClearMemory;如果去掉,虚拟内存和真实内存一起爆....请...
为什么这个过程.运行一段时候后,虚拟内存 ( 红框处 ) 就彪到3个G,然后就out of memory. 试过去掉ClearMemory;如果去掉,虚拟内存和真实内存一起爆....请高人指点啊.给个方向也好..
代码如下:
procedure TForm1.Button1Click(Sender: TObject); var URL_929 : string; idhttp1 : TIdHTTP; F : TextFile; list : TStringList; json :string; begin IdHTTP1 := TIdHTTP.Create(nil); IdHTTP1.ReadTimeout := 30000; IdHTTP1.Request.Accept := '*/*'; IdHTTP1.Request.AcceptLanguage := 'zh-cn'; IdHTTP1.Request.AcceptEncoding := 'gzip, deflate'; IdHTTP1.Request.UserAgent :='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)'; IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoKeepOrigProtocol]; IdHTTP1.ProtocolVersion:=pv1_1; AssignFile(F,'K.csv'); rewrite(F); closefile(F); dn:=0; repeat ci:=0; List:=TStringList.Create; repeat url_929:='http://www.xxxx.com'; if b then begin json:= nxgeturl(idhttp1,URL_929,debug1,edit1,5000);//自写的idhttp函数. if (Length(json)>6) and (Pos('对不起,页面不存在!',json)=0) then begin list.Add(m_json(json).Text);//这个是自写的处理json的函数. end else unit3.Form3.bigdebug.Lines.Add(button16.Caption+':错误 '+ c58+' | '+c59); end else exit; Application.ProcessMessages; ci:=ci+1; until ci=memo2.Lines.Count; Append(F); Write(F,list.Text); CloseFile(F); FreeAndNil(list); ClearMemory; dn:=dn+1; until dn = Trunc(dtp2.Date) - Trunc(dtp1.Date) + 1; ClearMemory; end;//清理内存过程...procedure TForm1.ClearMemory;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); application.ProcessMessages;
end;
end; 展开
代码如下:
procedure TForm1.Button1Click(Sender: TObject); var URL_929 : string; idhttp1 : TIdHTTP; F : TextFile; list : TStringList; json :string; begin IdHTTP1 := TIdHTTP.Create(nil); IdHTTP1.ReadTimeout := 30000; IdHTTP1.Request.Accept := '*/*'; IdHTTP1.Request.AcceptLanguage := 'zh-cn'; IdHTTP1.Request.AcceptEncoding := 'gzip, deflate'; IdHTTP1.Request.UserAgent :='Mozilla/5.0 (compatible; MSIE 6.0; Windows NT 5.1)'; IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoKeepOrigProtocol]; IdHTTP1.ProtocolVersion:=pv1_1; AssignFile(F,'K.csv'); rewrite(F); closefile(F); dn:=0; repeat ci:=0; List:=TStringList.Create; repeat url_929:='http://www.xxxx.com'; if b then begin json:= nxgeturl(idhttp1,URL_929,debug1,edit1,5000);//自写的idhttp函数. if (Length(json)>6) and (Pos('对不起,页面不存在!',json)=0) then begin list.Add(m_json(json).Text);//这个是自写的处理json的函数. end else unit3.Form3.bigdebug.Lines.Add(button16.Caption+':错误 '+ c58+' | '+c59); end else exit; Application.ProcessMessages; ci:=ci+1; until ci=memo2.Lines.Count; Append(F); Write(F,list.Text); CloseFile(F); FreeAndNil(list); ClearMemory; dn:=dn+1; until dn = Trunc(dtp2.Date) - Trunc(dtp1.Date) + 1; ClearMemory; end;//清理内存过程...procedure TForm1.ClearMemory;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
SetProcessWorkingSetSize(GetCurrentProcess, $FFFFFFFF, $FFFFFFFF); application.ProcessMessages;
end;
end; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询