• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi7程序出现“EOSError code8-存储不足”问题的分析与解决

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

1,故障现象

 

 

 

 

 

程序长期运行后,出现"System Error. Code: 8. 存储不足,无法处理此命令"错误。

 

此时检查磁盘空间是足够的。但打不开任务管理器。cmd命令行窗口都打不开。

关闭出错程序后,也无法重启。必须重启操作系统才能恢复正常。

 

 

2,错误分析

https://stackoverflow.com/questions/507853/system-error-code-8-not-enough-storage-is-available-to-process-this-command

 

上文显示,“Delphi apps are leaking atoms, leaving the id of your app without dropping it off from memory”,Delphi7使用了RWM Atom进行消息通信,但系统无法自动释放,当16K的空间被分配完后,就会弹出该错误。

 

采用ATOMTableMonitor程序观察发现,RWM ATom的消耗每天约增加2000,因此很快16K的空间将耗尽,最终将导致错误。

 

 

 

 

 

 

 

3,解决方案

http://cc.embarcadero.com/Item/28963

以上网站提供了释放RWM Atom资源的补丁。其中修复原理为Atom重复使用,避免不断分配新的Atom,具体说明如下:

 

There is a file called "RWMFixUnit.pas" that contains the hack, it replaces the call to RWM in the Controls unit and uses the GlobalAtom value (that will get cleaned up) 
instead of the leaky RWM. You HAVE to add this unit before the Controls (otherwise it will complain!) and it will only work in statically linked applications.
I have simplified the implementation, so it will just reuse the global atom for the "ControlOfs" leak, all other RWM allocation will proceed as normal.

 

 

实际操作中,发现在Dephi7中编译"RWMFixUnit.pas" 文件时,出现错误

function IntrRegisterWindowMessage(lpString: PWideChar): UINT; stdcall;

begin

     Result := 0;

     try

       if Pos('ControlOfs',lpString) = 1 then Result := GlobalFindAtom(lpString);

       //This is for defensive reasons... not really needed

       if Result = 0 then

       begin

          //if we get here we know that the GlobalAtom has not been allocated yet

          //so this is ***not*** the leaky ControlOfs RWM as Atom

          if @OrgRWMPtr <> nil then

               Result := OrgRWMPtr(lpString);

 

 

原因是GlobalFindAtom不接受PWideChar类型的参数。

因此,注意要修改为以下:

 

function IntrRegisterWindowMessage(lpString: PChar): UINT; stdcall;

begin

     Result := 0;

     try

       if Pos('ControlOfs',lpString) = 1 then Result := GlobalFindAtom((lpString));

       //This is for defensive reasons... not really needed

       if Result = 0 then

       begin

          //if we get here we know that the GlobalAtom has not been allocated yet

          //so this is ***not*** the leaky ControlOfs RWM as Atom

          if @OrgRWMPtr <> nil then

               Result := OrgRWMPtr(PWideChar(lpString));

 

 

修改后的程序,经过多日观察,RWM Atom的消耗一直保持稳定。问题得到解决。

 

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
MATLAB入门学习(六)发布时间:2022-07-18
下一篇:
paper79:MATLAB函数,interp1发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap