简体   繁体   English

C ++ / MFC应用程序中的内存不足错误

[英]Out of Memory error in C++/MFC app

I have an old Doc/View C++/MFC app that is developed using VS 6. I use Stingray Objective Grid 8.01 Pro as my data grid. 我有一个使用VS 6开发的旧Doc / View C ++ / MFC应用程序。我将Stingray Objective Grid 8.01 Pro用作数据网格。

Recently, our "job" sizes have gotten much larger; 最近,我们的“工作”规模越来越大。 and this is when the Out of Memory errors started showing up. 这是内存不足错误开始出现的时候。

Here is the scenario that gives me the out of memory error: 这是使我出现内存不足错误的情况:

FYI, when I say I load a job in the scenario below; 仅供参考,当我说要在以下情况下加载工作时; it means that I read a DB and load the data associated with that job into memory using custom classes that hold the data in CArray and CList objects; 这意味着我读取了一个数据库,并使用将数据存储在CArray和CList对象中的自定义类将与该作业关联的数据加载到内存中。 which is stored in the document class. 存储在文档类中。 In addition, I store some of that data in two StingRay grids on the main View for that document. 另外,我将某些数据存储在该文档的主视图上的两个StingRay网格中。

When I first open the application, it shows about 21 MB memory usage in Task Mgr. 当我第一次打开该应用程序时,它在Task Mgr中显示大约21 MB的内存使用情况。 I start by loading a typical job and the app goes to around 40 MB. 我首先加载一份典型的工作,然后该应用程序将达到40 MB。 I then load a "large" job and then application grows to around 159 MB. 然后,我加载一个“大”作业,然后应用程序增长到大约159 MB。 Next, I close the "large" job and the application drops to around 40 MB. 接下来,我关闭“大”作业,应用程序下降到大约40 MB。 I then load the same "large" job again and it goes back to around 159 MB. 然后,我再次加载相同的“大”作业,它返回到大约159 MB。 I then open a modeless window that contains a StingRay grid and fill the grid with data from the job. 然后,我打开一个包含StingRay网格的无模式窗口,并用作业中的数据填充该网格。 When that is doen, the application memory usage jumps to around 1,421 MB. 完成后,应用程序内存使用量将跃升至约1,421 MB。 I then close the modeless window and it goes back to around 163 MB. 然后,我关闭无模式窗口,然后恢复到大约163 MB。 I then close the "large" job and it goes back to around 45 MB. 然后,我关闭“大型”作业,它又回到了约45 MB。 I then try to reopen the same "large" job and when I starting reloading the Stingray grids on the main window (not the modeless window), I get an Out of Memory error. 然后,我尝试重新打开相同的“大”作业,当我开始在主窗口(而非无模式窗口)上重新加载Stingray网格时,出现内存不足错误。 At that point, the application is showing about 170 MB in Task Manager. 那时,应用程序在任务管理器中显示了大约170 MB。

Since I can close and reopen jobs without any issue, I can only assume that when I am loading the data into the Stingray grid in the modeless window; 因为我可以关闭并重新打开作业而没有任何问题,所以我只能假定将数据加载到无模式窗口中的Stingray网格中时,只能进行以下操作: that something is not getting freed; 没有释放一些东西; but if that is the case, why is my memory usage in Task Manager seem to be going back to a nearly normal level after I close the modeless window. 但是如果是这样的话,为什么在关闭无模式窗口后,任务管理器中的内存使用率似乎恢复到接近正常水平。 It is only about 5 MB larger after I close the modeless window. 关闭无模式窗口后,它只有大约5 MB。

What I really need is some suggestions on how to try and identify why I am getting this out of memory error when my app has only used 160 MB when it says out of memory. 我真正需要的是一些有关如何尝试确定为什么我的应用程序仅在内存不足时仅使用160 MB内存错误的建议。

Any help would be appreciated. 任何帮助,将不胜感激。

Thanks, 谢谢,

Phil 菲尔

Getting 1,421 MB when loading the grid is uncomfortably close to the 2GB address range that you are allowed in a 32-bit app. 加载网格时获得1,421 MB的空间非常接近32位应用程序所允许的2GB地址范围。 The surefire solution, of course, is to become a 64-bit app, if that is possible. 当然,surefire解决方案将尽可能成为一个64位应用程序。 Another thing you could try is to use the grid's virtual mode, so the grid does not have to duplicate the data. 您可以尝试的另一件事是使用网格的虚拟模式,因此网格不必复制数据。 In the virtual mode you get a callback for each row or cell to be painted and you give it the data from your document storage. 在虚拟模式下,您将获得要绘制的每一行或单元格的回调,并从文档存储中为其提供数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM