内存泄漏,窗口是否有保护措施以防止达到最大内存? [英] Memory leak, does window have a safeguard to prevent max memory reached?

查看:39
本文介绍了内存泄漏,窗口是否有保护措施以防止达到最大内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用第三方API的应用程序,我认为他们有内存泄漏问题.我编写了一个小测试程序(如下)进行测试,请注意,VMIListener和VMI都来自我正在实现其虚拟接口方法的API.

I have an application that uses a 3rd party API and I think they are having a memory leak issue. I wrote a small test program (below) to test this out, please note, both VMIListener and VMI are from the APIs in which I'm implementing their virtual interface methods.

如果我注释掉VMI vmi,则没有任何内存泄漏行为;在我的VMITest课上.以我对C ++的有限了解,我认为这是因为虚拟VMI类没有虚拟析构函数.

I don't have any memory leak behavior if I comment out the VMI vmi; under my VMITest class. With my limited knowledge in C++ I assume this is because the virtual VMI class does not have the virtual destructor.

但是,我的问题是窗口是否有适当的保护措施以最大限度地避免内存泄漏?因为我在Window Task Manager中看到了一个有趣的结果.

However, my question is does window have some safeguard in place for maxing out memory from memory leak? because I see an interesting result within the Window task Manager.

如果我运行测试程序,它将自动跳大约2 Gig,并停留在那里(第一个白色圆圈区域).如果我运行我的实际应用程序(第二个白色区域),则泄漏缓慢地达到大约相同的水平(5.8 Gig),并且在两种情况下,泄漏都在那里停止,而没有进一步增加内存.我运行了其他一些测试,在这些测试中,我的应用程序得以运行,当泄漏达到特定的内存使用水平时,泄漏就停止了.

If I run my test program, it automatically jumped by roughly 2 Gigs and stays there (the first white circle area). If I run my actual application (2nd white area), the leak slowly reach up to about the same level (5.8 Gig) and in both case they stop there without further increase in the memory. I run several other tests where I let my application running, the leak stops when they reach this specific level of memory usage.

void main(int cArgs, char* saArgs[])
{
     VMITest    *m_pVMI;

     while(true)
     {
         m_pVMI = new VMITest();
         delete m_pVMI;
         m_pVMI = NULL;
     }
 }


 class VMITest : public VMIListener
 {

    public:
           VMI  vmi;
           VMITest();

    // VMIListener interface methods.
 };

 class VMI_API VMI
 {
   public:
         VMI();
   //some more functions
 }

推荐答案

在Windows上,默认情况下,即使在64位Windows操作系统上,32位应用程序的地址空间也为2GB.分配的内存超过您的地址空间将失败.

On windows 32 bit applications by default have an address space of 2GB even on a 64 bit windows OS. Allocation of memory more than your address space will fail.

可以使用/LARGEADDRESSAWARE链接器选项将此限制扩展到32位窗口上的3GB或64位窗口上的4GB.

It is possible to use the /LARGEADDRESSAWARE linker option to extend this limit to 3GB on 32bit windows or 4GB on 64 bit windows.

这篇关于内存泄漏,窗口是否有保护措施以防止达到最大内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆