Finding where memory was last freed?

前端 未结 3 1916
夕颜
夕颜 2021-01-19 17:26

Very general: Is there an easy way to tell which line of code last freed a block of memory when an access violation occurs?

Less general:

3条回答
  •  花落未央
    2021-01-19 18:01

    Short answer: no.

    What you need is a debug malloc. I don't keep up with Windows any longer but there are several about, including this free one.

    Update

    Looks like Visual Studio C has a built in version. See here

    When the application is linked with a debug version of the C run-time libraries, malloc resolves to _malloc_dbg. For more information about how the heap is managed during the debugging process, see The CRT Debug Heap.

    ... and see here for _malloc_dbg.

提交回复
热议问题