且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

不是在动态分配的对象上调用delete总是内存泄漏?

更新时间:2023-11-13 13:58:10

第二种情况不是内存泄漏。

这不是一个泄漏,因为你仍然有一个指向分配的内存的指针。

要定义内存泄漏,我想坚持定义哪些大多数内存分析工具,如valgrind使用:

Second case is not a memory leak.
It is not a leak because you still have an pointer to the memory that was allocated.
To define a memory leak I would like to stick to definition which most of memory analysis tools like valgrind use:


内存已分配,不能随后释放,因为程序不再有任何指针到分配的内存块。

Memory was allocated and cannot be subsequently freed because the program no longer has any pointers to the allocated memory block.