如何使用DrMemory在C ++中显示和报告内存泄漏?

时间:2014-08-20 21:19:58

标签: c++ memory memory-leaks

我正在尝试使用DrMemory,因为它似乎是一个易于使用的Windows内存泄漏检测工具:http://www.drmemory.org/

我故意在下面创建了可能存在内存泄漏的c ++应用程序。

#include <iostream>
using namespace std;

class Dog{
public:
    int a;
    string b;
    Dog()
    {
        a = 1;
        b = "alfred";
    }

    ~Dog()
    {

    }
};

class Example{
public:
    Dog* d1;
    Dog* d2;
    string a;
    int b;

    Example()
    {
        a = "test";
        b = 15;
        d1 = new Dog();
        d2 = new Dog();
    }

    ~Example()
    {
        //delete d;
    }

};

void createObjects(){
    for(unsigned int i=0; i < 200; i++)
    {
        Dog* d = new Dog();
        Example* b = new Example();
    }

    Dog* d = new Dog();
    d = NULL;
    Example* b = new Example();
    b = NULL;
}

int main()
{
    createObjects();
    return 0;
}

在构建此应用程序以及以下选项(根据DrMemory文档的指示)“ - ggdb -static-libgcc -static-libstdc ++”之后,我用drmemory.exe执行了可执行文件,就像这样:

drmemory.exe TestingDrMemory.exe

但是,我没有看到任何与内存泄漏有关的错误/日志消息,我无法识别源代码中出现这种情况的行。 DrMemory有可能这样吗?使用它来识别/检测源代码中导致内存泄漏的行的正确方法是什么?

日志如下:


Dr. Memory version 1.7.0 build 5 built on Apr  4 2014 23:38:05
Dr. Memory results for pid 18240: "TestingDrMemory.exe"
Application cmdline: "TestingDrMemory.exe"
Recorded 104 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin\suppress-default.txt

===========================================================================
FINAL SUMMARY:

DUPLICATE ERROR COUNTS:

SUPPRESSIONS USED:

NO ERRORS FOUND:
      0 unique,     0 total unaddressable access(es)
      0 unique,     0 total uninitialized access(es)
      0 unique,     0 total invalid heap argument(s)
      0 unique,     0 total GDI usage error(s)
      0 unique,     0 total handle leak(s)
      0 unique,     0 total warning(s)
      0 unique,     0 total,      0 byte(s) of leak(s)
      0 unique,     0 total,      0 byte(s) of possible leak(s)
      0 unique,     0 total,      0 byte(s) of still-reachable allocation(s)
ERRORS IGNORED:
      2 potential error(s) (suspected false positives)
         (details: C:\Dr. Memory\DrMemory-TestingDrMemory.exe.18240.000\potential_errors.txt)
     18 potential leak(s) (suspected false positives)
         (details: C:\Dr. Memory\DrMemory-TestingDrMemory.exe.18240.000\potential_errors.txt)
Details: C:\Dr. Memory\DrMemory-TestingDrMemory.exe.18240.000\results.txt

0 个答案:

没有答案