How to check deallocation of memory

前端 未结 7 1315
猫巷女王i
猫巷女王i 2020-12-03 21:59

How to check if memory to which pointer p points has been succesfully deallocated?

相关标签:
7条回答
  • 2020-12-03 22:38

    In C++, you can safely assume deallocation never fails. Destructors must not throw exceptions, and the actual memory reserved should never fail to be released, so given those two points, nothing can go wrong.

    However, if you delete a pointer that has already been deleted, your program will probably crash. This isn't a problem with deallocation itself though - the original delete worked successfully. It's a problem with your program's memory management if it tries to delete a pointer twice, but that's rarely necessary with modern STL and smart pointers like std::vector, std::unique_ptr, etc...

    0 讨论(0)
提交回复
热议问题