[超难]这么简单的程序为什么在运行的时候内存不断增加?
这么简单的程序为什么在运行的时候内存不断增加?
在VC6.0 和 VC7.1都试过了。
=========================================
#include <windows.h>
#include <vector>
typedef std::vector <int> IntVectorType;
class Interface
{
public:
virtual void Do()=0;
};
class Test : public Interface
{
public:
Test(const IntVectorType& nums)
: _nums(nums)
{
}
virtual void Do(){};
private:
IntVectorType _nums;
};
int main(int argc, char* argv[])
{
IntVectorType ints;
ints.push_back(0);
ints.push_back(1);
ints.push_back(2);
ints.push_back(3);
while ( 1 )
{
Interface* p = new Test(ints);
p-> Do();
delete p;
Sleep(10);
}
return 0;
}
[解决办法]
Interface没有虚析构函数!
[解决办法]
while ( 1 )
{
Interface* p = new Test(ints); //不断分配内
p-> Do();
delete p; //释放内存.但Interface没有虚析构函数,故释放内存要
Sleep(10); //出问题
}
在Interface类里加上一句
virtual ~Interface(){}
[解决办法]
baseclass: Interface没有虚的析构函数
[超难]这么简单的程序为什么在运行的时候内存不断增加?该怎么处理
[超难]这么简单的程序为什么在运行的时候内存不断增加?这么简单的程序为什么在运行的时候内存不断增加?在V
