Invalid Pointer Operation - Delphi XE

前端 未结 4 1585
庸人自扰
庸人自扰 2021-01-02 05:20

I can\'t seem to figure this one out. My program compiles and runs successfully, but during debugging only it pops up a message box saying \"Invalid Pointer Operation\" when

4条回答
  •  隐瞒了意图╮
    2021-01-02 05:29

    Invalid pointer operations occur when you tell the Delphi memory manager to release memory that doesn't belong to it. There are three ways that might happen:

    • Freeing a pointer or object that has already been freed.
    • Using FreeMem to free something that was allocated by some other memory manager (such as GlobalAlloc or CoTaskMemAlloc).
    • Freeing an uninitialized pointer. (This is distinct from freeing a null pointer, which is completely safe.)

    Somewhere in your program, you are doing one of those things. The debugger has detected the exception thrown by the memory manager, so do some debugging. From the stack trace, you should be able to see which variable you're trying to free. Check the rest of your program for other ways that variable is used.

    Tools like MadExcept and Eureka Log can help you find double-free errors. They can keep track of where the pointer in question got allocated and where it was freed the first time, and that is sometimes enough information to figure out your mistake and stop freeing things multiple times.

提交回复
热议问题