what to do if debug runs fine, but release crashes

I have an application that runs just fine in the debug build, but when I start it in the release build, I get a

unhandled Exception at 0x0043b134 in myapp.exe: 0xC0000005:
Access violation while reading at position 0x004bd96c

If I click on 'break' it tells me that there are no symbols loaded and the source code can't be displayed.

What can I do in such a situation to track down the problem?


This kind of problem is often due to unitialized variables. I'd start there looking for your problem.

Debug mode is more forgiving because it is often configured to initialize variables that have not been explicitly initialized.

Perhaps you're deleting an unitialized pointer. In debug mode it works because pointer was nulled and delete ptr will be ok on NULL. On release it's some rubbish, then delete ptr will actually cause a problem.


It could be two things:

  • One or more of your assertions does necessary work apart from the check itself
  • Something else
  • To rule out the former, try redefining assert as an empty operation in the debug build. If the absence of some assertion causes the crash, you will see it. Otherwise, it's something else.

    Also, I assume you have version control. Did this just start happening? You can analyze the code changes from last week.

    Finally, even in the absence of a crash in debug mode, running a memory checker tool may be useful to spot incorrect memory access.


    Two steps:

    a) Build release build with debug symbols (possible with VS at least)

    b) Build release build without optimization

    If the problem still happens, it is very good and easy to fix. It is almsot as if the problem is in debug build.

    If the problem happens with optimization settings on, then it is really tough and has to be handled in situation specific manner.

    链接地址: http://www.djcxy.com/p/82302.html

    上一篇: 立即检测Windows上的堆损坏错误。 怎么样?

    下一篇: 如果调试运行正常,该怎么办,但释放崩溃