When you debug optimized code, information in debugger panes may lead you to suspect logic problems that do not actually exist. You should bear in mind the points below.
Values in some monitors may not be current
Do not rely on monitors such as the Local Variables or Popup monitors to show the current values of variables. Numeric and char values may be kept in processor registers, as may pointers to other types of variables such as strings and class objects. In the optimized program, these values and pointers are not always written out to memory; in some cases, they may be discarded because they are not needed.
Static and external variables are not always current
Static or external variables can be monitored at function entry and exit points. Within an optimized function, their values may be optimized out of existence.
Register and Storage monitors are always current
The register and storage monitors are correct. Unlike monitors that show actual variables, such as the Local Variables or Popup monitors, the Register and Storage Monitors are always up-to-date as of the last time execution stopped.
Source statements may be optimized away
Use the disassembly view of your program to see whether source statements whose result you were relying on have been optimized away (via dead code elimination, where code that performs no useful work is removed). You may find, for example, that an assignment to a variable in your source code does not result in any disassembly code being produced; this may indicate that the variable's value is never used after the assignment.