when you use "new" the memory normally will be allocated in heap rather than stack so it is your program's responsibility to call "delete" to free the memory allocated in heap. Otherwise memory leakage will occurs, and probably will crash your system. Because the OS will automatically free the memory which is in stack but not the heap. Mind that in VC++ if you use the "Debug" version even you forget to call the "delete" after a calling to "new" the memory VC++ will take care of that, but not in "Release" version. Another point might worth of reminding is that: dynamically allocates mulit-dimension array needs the "delete" to be matched exactly.
《Effective C++》?
我想答案是肯定的
不过要够狠才行(狂new那些占内存的对象N次)
最好自己创建一个局域堆,然后分配/释放同样大小的内存块都在这个堆中进行。
参考《Windows核心编程》
的。
malloc<--->free
vc将你分配的小内存在另外的堆分配,与大内存分开,所以不论大小内存,都不至于会很容易造成碎片。
我做课程设计时也经常用NEW和DELETE 运行时没出现问题啊
如果只用NEW没有DELETE就回造成内存浪费而就会出现死机
在《C++》教程就有解释!!!