Original: http://hi.baidu.com/leggle/blog/item/ec0c2e5400c3ed5dd10906a7.html
Oh, Iris's here. Due to the recent completion of the project near the end, want to run under release but found this problem, then search online, excerpt as follows: VC program in Debug Normal, under release error
Possible reasons for the existence of:
1. Memory allocation problem
(1) Variable initialization
Release the requirements of the program is more stringent than debug, all variables (especially pointers and bool type) should be initialized before use.
(2) The problem of data overflow
such as: Program segment Char buffer[4]; int num; strcpy (buffer, "ABCD");
In debug edition, the null of buffer overwrites the high of NUM, but there is no problem unless num >16m. However, in release, Num may be placed in a register so that null overwrites the space below buffer, possibly the return address of the function, which causes access ERROR.
(3) different memory allocation methods
If you are applying ele to 6*sizeof (DWORD) =24bytes in the debug version, you are actually assigned 32bytes (the debug version is allocated in 32bytes), and in the release version, Assigned to you is 24bytes (release version in 8bytes units), so in the debug version if you write Ele[6], there may be no problem, and in release version, there is access violate
2. User-defined messages should be used in a defined way
For user-defined messages: #define WM_USERMESSAGENAME wm_user+1
On_message definition: On_message (wm_usermessagename, Onusermessagename), the macro requires two parameters, if the message response function does not have parameters, the compiler will be pushed out of the stack when the error occurs, While the debug version of the runtime compiler will automatically add some test code, so it does not cause stack corruption.
WORKAROUND: 1) Replace the on_message with on_message_void (header file <afxpriv. h>), the macro does not require parameters
2) Modify the message response function: afx_msg void Onusermessagename (WPARAM WPARAM, LPARAM LPARAM)//must add parameter, no need to get
3. Assert and verify
The assert will not be compiled in release version and will cause errors if there is space allocation in the Assert. You can change to verify.
4. Memory allocation
Ensure consistency in data creation and cleanup: If a DLL provides a function to create data, the DLL should also provide a function to destroy the data. The creation and cleanup of data should be on the same level.
5. DLL disaster
If your program uses your own DLL, please note that:
1) It is not possible to mix debug and release versions of DLLs together. Debug is the debug version, release version is release version.
2) never assume that the static connection library will solve the problem, which will only make the situation worse.
6. Change the optimization option under Project Settings c++/c to Disable (Debug)
The compiler's optimizations can lead to many unexpected errors.
Reference: http://www.cygnus-software.com/papers/release_debugging.html
Also attached ZZ:
(1) Frame pointer (frame Pointer) ellipsis (FPO): All invocation information (return address, parameters) and automatic variables are placed in the stack during a function call. If the Declaration and implementation of the function is different (parameter, return value, call method), it will produce an error ———— but in the Debug mode, the access of the stack is implemented by the address saved by the EBP register, and if there are no errors (or "not many") in the array, the function will normally execute normally; Release mode, optimizations omit the EBP stack base pointer, so accessing the stack via a global pointer can cause the return address error to be a program crash. The strong-type nature of C + + can check for most of these errors, but it will not work if a forced type conversion is used. You can force the/oy-compilation option in the release version to turn off the frame pointer ellipsis to determine if such an error occurred.
(2) Volatile variable: volatile tells the compiler that the variable may be modified in an unknown way outside of the program (such as systems, other processes, and threads). Optimizer to improve program performance, some variables are often placed in registers (similar to the Register keyword), while other processes can only modify the memory in which the variable resides, while the value in the register does not change. If your program is multithreaded, or if you find that the value of a variable does not match your expectations and you are sure that the settings are correct, you are likely to encounter such a problem. This error sometimes manifests itself as a program with the fastest optimization error and minimal optimization. Try adding volatile variables that you think are suspicious.