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

idhttp.get以致程序的句柄增加

2013-03-01 
idhttp.get导致程序的句柄增加请问大牛们,我每次在执行idhttp.get程序的句柄就会增加,请问如何解决?//执行

idhttp.get导致程序的句柄增加
请问大牛们,我每次在执行idhttp.get程序的句柄就会增加,请问如何解决?

      //执行下载文件
      astream:=TFileStream.Create(LoadRoute+'\'+filename+'.dm',fmCreate);
      http:=TIdHTTP.Create(nil);
      http.Get(aurl,astream);
      //下载完毕后释放http、astream内存
      if http.Connected then
        http.Disconnect;
      if Assigned(http) then
        http.Free;
      if Assigned(astream) then
      begin
        freeandnil(astream);
      end;



[解决办法]
这个是create和free的问题,当free后,socket连接要等一会才断开。所以看到有N多的连接。
如果动态建立,最好create写到initialization里面,free写到finalization里面。这样就只有一个idhttp存在。
[解决办法]
astream:=TFileStream.Create(LoadRoute+'\'+filename+'.dm',fmCreate);       http:=TIdHTTP.Create(nil); 
try
 http.Get(aurl,astream);       //下载完毕后释放http、astream内存 
 if http.Connected then  
   http.Disconnect;    
except
end;
if Assigned(http) then      
   http.Free;  
if Assigned(astream) then     
begin     
  freeandnil(astream);     
end; 


热点排行