为啥new的对象要程序自己释放

#include 
#include 
class MyClass
{
public:
MyClass()
{
}


~MyClass()
{
}


private:


};
int _tmain(int argc, _TCHAR* argv[])
{
using namespace  std;
map*> appleMap;
for (int i=0;i<5;i++)
{
MyClass *mc = new MyClass();
list list1;  //局部变量,声明周期到后,其变量和内存区域马上被释放
list1.push_back(mc);
appleMap[i] = &list1;
}


map*> appleMap2;
for (int i=0;i<5;i++)
{
MyClass *mc = new MyClass();
list* list1=new list(); //内存区域在堆栈中, 一直保留 用完自己释放
list1->push_back(mc);
appleMap2[i] = list1;
}


你可能感兴趣的:(c++基础)