内存泄露 memory leak 的原因


#include <iostream>
using namespace std;

void foo()
{
    MyClass *x;
    x = new MyClass(); //指向的丢失了 两种解决方法:

    return x;

    delete[] x;
    x = NULL;
    return 0;
}

int main()
{
    int *x;
    x = new int[1000];//丢失了 
    x = new int[4000];
    delete[] x;
    x = null;
    return 0;
}

/* vim: set ts=4 sw=4 sts=4 tw=100 */
原文地址:https://www.cnblogs.com/i80386/p/4438971.html