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



Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • In this study, conducted by Forrester Consulting and commissioned by BMC, you'll find out why 93% of US and UK IT decision-makers surveyed consider capacity management important or very important to their cloud strategy. Learn how using capacity management to manage workloads in the cloud can help Increase flexibility and continuity for your organization.

  • Live Event Date: May 11, 2015 @ 1:00 p.m. ET / 10:00 a.m. PT One of the languages that have always been supported with the Intel® RealSense™ SDK (Software Developer Kit) is JavaScript, specifically so that web-enabled apps could be created. Come hear from Intel Expert Bob Duffy as he reviews his own little "space shooting" game where the orientation of your face controls the aiming reticle to help teach developers how to write apps and games in JavaScript that can use facial and gesture …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date