My code works in Debug mode, but not in Release mode

Nima picture Nima · May 27, 2010 · Viewed 9.5k times · Source

I have a code in Visual Studio 2008 in C++ that works with files just by fopen and fclose. Everything works perfect in Debug mode. and I have tested with several datasets. But it doesn't work in release mode. It crashes all the time. I have turned off all the optimizations, also there is no dependency to anything(in the linker), and also I have set these:

Optimization: Disabled(/Od) Keep Unreferenced Data. Do Not Remove Redundant Optimize for Windows98: NO

I still keep wondering how it should not work under these circumstances. What else should I turn off to let it work as in debug mode?

I think if it works in release mode but not in debug mode, it might be a coding fault but the other way looks weird. isn't it?

I appreciate any help. --Nima

Answer

Amardeep AC9MF picture Amardeep AC9MF · May 27, 2010

Debug modes often initialize heap data allocations. The program might be dependent on this behavior. Look for variables and buffers that are not getting initialized.