Tutorial :Optimization settings in VS


I am working on an application/GUI created with Win32/ATL . So there is UI field( text field) which works fine as designed in debug build. With release build it gets malformed and it looks like the width of text field is infinite. It works fine in debug build but creating issues in release build. So my question how same code can work in debug build and not working in release build. Is there any chance that it could be releated to optimization settings in release builds ? In release build we have optimization settings set to Minimum Size, Favour small code. Also when I try to debug release build ,it again works fine. Does debugging in release build removes optimization?

I want to reproduce the issue while debugging in release build or may be if possible in debug build. Any suggestions?


VC++ fills its runtime-memory in debug mode with special values. It does not ensure any fixed or zero-initialization though. Read this SO thread for details. Uninitialized Memory Blocks. These values may not crash the application every time.

I have run into similar situations some times. One common example is that accessing past the array boundaries is an error. Many a time this was not evident in debug mode but crashed in release builds. In general, the runtime is leniant in debug modes and provides more cover to programmer errors.

As others have pointed out, there is definitely some problem with the code; most probably uninitialized variables.


Try enabling the /RTC (Run-Time Error Checks compiler flag with the s option. This initializes local variables to a non zero value which helps diagnose uninitialized variables.


Off the top of my head: ensure that ASSERTs you're using do not contain any logic whatsoever, since these are discarded of in the release build.


It's nothing to do with optimisations. In a debug build, the compiler will typically initialise variables to known values, while in the release build it won't. The symptoms you describe are probably due to an uninitialised variable or pointer in your code.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »