Why doesn’t my project work in release mode?

Rule 1: Always regularly test both the Debug and Release mode versions of your applications.

Are you absolutely certain your program is working in Debug mode? I recently aided in sorting out what appeared to be a Debug -Vs- Release mode problem that turned out to be something else. So, make sure that the debug version works on the same machines that the release version fails on.

Rule 2: Never classify a problem as a Debug -Vs- Release mode problem unless you’ve tried both versions on several different machines.

Preprocessor Differences

One of the likely problems is caused by differences during compilation with preprocessor symbols. Try compiling your Debug version with the following changes:

  • In Project Settings (Alt-F7) under the C++/C tab set the category to “General” and change the “_DEBUG” preprocessor definition to “NDEBUG”.

  • Under the C++/C tab, set the category to “Preprocessor” and add the preprocessor definition “_DEBUG” to the “Undefined Symbols” edit field.

  • Recompile using “Rebuild All”

If this recreates your problems in your Debug version then make the following changes to your code:

  • Change all occurrences of ASSERT() to VERIFY().

  • Look for any code you’ve placed inside of a “#ifdef _DEBUG” wrapper that might be needed in the Release version.

  • Look for code in TRACE() must be executed. TRACEs like ASSERTs are compiled out in release mode.

If this fixes your problems in Debug mode, try rebuilding the Release mode version.

Rule 3: Be very cautious that you dont place code that must be executed in a place where it will be compiled out in release mode.

Variable Initialization Differences

Variables are often initialized differently in Debug versions than in Release version of software. If you’ve assumed that your variables are zeroed when they are declared could easily cause strange behavior in Release mode on Win9x. You can also introduce bugs that are Win9x specific. WinNT, for security reasons, zeros all memory before it is used.

Rule 4: Never assume that your variables are initialized unless you’ve explicitly initialized them in your code. This includes global variables, automatic variables, malloced data, and newed data.

Are You Ignoring Compiler Warnings?

It’s possible that turning up the compiler warning level will expose your problem. I always set compiler warnings to either “Level 3” or “Level 4” depending on how masochistic I’m feeling. Go through and resolve every compiler warning (this is a very good idea to do before you release your code anyway). This can expose initialization problems and many other potential errors that may be causing your problem.

Rule 5: When you start a project turn the warning level to “Level 3” or “Level 4” and make sure your code compiles with no warnings before you check your code in.

Have You Removed Any Resources?

If you have references to resources that have been removed from your resource file, your debug version may work but your release version may crash.

Rule 6: Make sure all references to resources are removed when you delete them from your resource file. This includes references in resource.h.

Debugging in Release Mode

It is possible to debug in Release mode. The first step is to turn on symbols:

  • In Project Settings (Alt-F2) under the “C++/C tab” set the category to “General” and change the Debug Info setting to “Program Database”.

  • Under the “Link tab” check the “Generate Debug Info” tab.

  • Recompile using “Rebuild All”

This will allow you to see the symbols in the release version. You might want to also consider the following:

  • You may want disable your optimization settings when debugging your release version (though this isn’t absolutely necessary).

  • If you have trouble placing breakpoints, the command “__asm {int 3}” will cause your program to stop at that line (be sure to remove these lines from your program when you are done debugging).

Debugging in release mode has several limitations.

  • The most annoying one is that you can’t easily see into MFC because you don’t have the symbols included for the MFC DLL.

  • You must add symbols to the release versions of all libraries and DLL’s you wish to debug in your release application.

Date Posted: 01/18/99

More by Author

Must Read