c++ - Visual Leak Detector 未发现泄漏 VS2013

标签 c++ visual-studio memory-leaks visual-leak-detector

无论我如何尝试,我似乎都无法让 VLD 捕捉到任何内存泄漏。有什么想法吗?

这里也是输出的片段:

Visual Leak Detector Version 2.4RC2 installed. 
The thread 0x5748 has exited with code 0 (0x0).
The thread 0x2c70 has exited with code 0 (0x0).
The thread 0x3c98 has exited with code 0 (0x0).
No memory leaks detected.
Visual Leak Detector is now exiting.
The program '[24988] ConsoleApplication2.exe' has exited with code 0 (0x0).


#include <vld.h>

#include <iostream>
using namespace std;

class Car{
    public:
        Car() {}

        Car(string model,int year, string color) {
            this->model = model; this->color, this->year = year;
        }

        string getModel() {
            return this->model;
        }

        void setModel(string m) {
            this->model = model;
        }

        string getColor() {
            return this->color;
        }

        void setColor(string color) {
            this->color = color;
        }

        void paint()
        {
            setColor("white");
        }

    private:
        string model;
        int year;
        string color;
};


int _tmain(int argc, _TCHAR* argv[]){
    Car c("bmw", 2000, "red");
    c.paint();
    cout << c.getColor().c_str();

    for (int i = 0; i < 10; i++)
        int *ptr = new int(10);

    Car *c2 = new Car("benz", 2010, "yellow");

    return 0;
 }

我错过了什么?

最佳答案

在visual studio 2013 ultimate下运行

你必须在控制台模式下执行程序(转到项目的调试目录)

在下面,你会看到结果的图片,但是控制台显示了很多泄漏,我们在这里看不到所有这些

我在项目设置中添加了 include 和 lib 路径

  1. C:\Program Files (x86)\Visual Leak Detector\include
  2. C:\Program Files (x86)\Visual Leak Detector\lib\win32
  3. C:\Program Files (x86)\Visual Leak Detector\lib\win64

enter image description here

如您所见,有 13 次内存泄漏。

关于c++ - Visual Leak Detector 未发现泄漏 VS2013,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33180597/

相关文章:

c++ - 使用 Boost.Asio 连接到域以托管服务器

c++ - 跳过第 3 方库中的 #define

c++ - C++ 中可以返回字符串对象的局部变量吗?

java - 哪一项指示了 java 应用程序的确切内存使用情况

memory-leaks - clGetPlatformIDs 内存泄漏

c++ - 如何在 for 循环中使用第三个参数?

c++ - 在 cppunit 测试中 stub WinBase.h

ios - Facebook 在 Visual Studio 的 Xamarin ios 中以编程方式注销

visual-studio - 我可以从 Visual Studio 中的格式文档中排除部分代码吗

visual-studio - 从 C++/CLI 旧语法 : How to and can this be automated? 转换