s*******t 发帖数: 2896 | 1 c++里,如果一个程序new了很多object而不delete,那么当程序正常结束以后,系统会
不会把申请的内存收回呢?还是这个程序运行若干次以后,操作系统因为内存耗尽而瘫
痪?
谢谢! |
T*****9 发帖数: 2484 | 2 会的
【在 s*******t 的大作中提到】 : c++里,如果一个程序new了很多object而不delete,那么当程序正常结束以后,系统会 : 不会把申请的内存收回呢?还是这个程序运行若干次以后,操作系统因为内存耗尽而瘫 : 痪? : 谢谢!
|
s*******t 发帖数: 2896 | 3 是会回收,还是会crash?
【在 T*****9 的大作中提到】 : 会的
|
P********e 发帖数: 2610 | 4 回收
【在 s*******t 的大作中提到】 : 是会回收,还是会crash?
|
n**d 发帖数: 9764 | 5 Is there any way to check if the allocated memory is deleted? In other words
, how could we check memory leaking?
【在 P********e 的大作中提到】 : 回收
|
f*******y 发帖数: 988 | 6 c++全靠自己小心了
words
【在 n**d 的大作中提到】 : Is there any way to check if the allocated memory is deleted? In other words : , how could we check memory leaking?
|
h********g 发帖数: 116 | 7 好像有一些工具
words
【在 n**d 的大作中提到】 : Is there any way to check if the allocated memory is deleted? In other words : , how could we check memory leaking?
|
k**f 发帖数: 372 | 8 If possible, you should use new in constructors and delete in desstructors.
So at the end of your program, all the allocated memory will be released.
If you use the right library, such as STL containers, and the right type of
smart pointers (look for them in boost.org or search "C++ TR1"), you seldom
need to use new and delete in your code. Then you don't have to worry about
memory leak caused by unmatched new and delete. |