How to detect “dangling pointers” if “Assigned()” can't do it?

后端 未结 6 1663
闹比i
闹比i 2020-12-03 17:22

In another question, I found out that the Assigned() function is identical to Pointer <> nil. It has always been my understanding that

6条回答
  •  一整个雨季
    2020-12-03 17:52

    Use a memory manager, such as FastMM, that provides debugging support, in particular to fill a block of freed memory with a given byte pattern. You can then dereference the pointer to see if it points at a memory block that starts with the byte pattern, or you can let the code run normallly ad raise an AV if it tries to access a freed memory block through a dangling pointer. The AV's reported memory address will usually be either exactly as, or close to, the byte pattern.

提交回复
热议问题