DELPHI频繁调用API函数后因系统资源不足而死机怎么办? (100分)

  • 主题发起人 主题发起人 chenglf
  • 开始时间 开始时间
C

chenglf

Unregistered / Unconfirmed
GUEST, unregistred user!
我用DELPHI编写的一个程序,要频繁调用API函数(放在循环里面),但我以现每调用一次其占用内存就多一点,最后竟然占用内存之20M之多,最后因系统资源不足而死机,请问怎么释放该内存?
 
是API的问题么?
 
是什么API?
 
程序中使用了如下API函数:GetDC;GetPixel;setPixel;mouse_event
 
同样的方法用编写很正常。
 
应该不是API的问题吧,把相关的代码贴出来好吗?
 
肯定不是 API 的问题,我用了那么多 API 也没什么错
 
下面是出错的源程序,将它拿下后运行很正常,该代码在定时器内,<br>每分钟执行一次,执行一次后约多占用100K内存,直至死机。<br>请高手解答。里面的函数均未声明,不知是否有关系?同样的代码用VB6很正常。<br>if &nbsp;aa=strtoint(Edit91.text) then<br>begin<br>&nbsp; &nbsp;if GetPixel(GetDC(0),500,15)=strtoint(Edit92.text) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; if GetPixel(GetDC(0),420,53)=strtoint(Edit93.text) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_ABSOLUTE +MOUSEEVENTF_MOVE,450*65535 &nbsp;Div (screen.Width),53*65535 &nbsp;Div (screen.Height),0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_LEFTUP,0,0,0,0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; aa:=47;<br>&nbsp; &nbsp; &nbsp; while aa&lt;&gt;12345678 do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aa:=aa+1;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetPixel(GetDC(0),56,25)=strtoint(Edit93.text) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if GetPixel(GetDC(0),aa,53)&lt;&gt;strtoint(Edit92.text) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetPixel(GetDC(0),aa+9,53)=strtoint(Edit92.text) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_ABSOLUTE +MOUSEEVENTF_MOVE,(mytime_desktopdollars+30)*65535 &nbsp;Div (screen.Width),53*65535 &nbsp;Div (screen.Height),0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_LEFTDOWN,0,0,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mouse_event( MOUSEEVENTF_LEFTUP,0,0,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;aa:=12345678;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; aa:= aa+70;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if aa&gt;500 then aa:=12345678;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;aa:=0;<br>end;<br>
 
使用 GetDC 获得的 HDC 要释放!<br>用ReleaseDC!<br>
 
接受答案了.
 
后退
顶部