How to check deallocation of memory

前端 未结 7 1335
猫巷女王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:18

    In few words: you can't.

    Check out tools like Valgrind to help you debugging memory leaks issues.

    Some other things you should consider:

    • Use smart pointers so that you don't have do think about memory management,
    • Set your pointers to 0 after you free them, so that a further delete has no effect,
    • Use standard classes (vector, ...) instead of rolling your own,
    • Finally, don't use pointers (actually you almost can)

提交回复
热议问题