In the build settings panel of VS2010 Pro, there is a CheckBox with the label \"optimize code\"... of course, I want to check it... but being unusually cautious, I asked my
.net compiler optimization could cause bugs. happend to me today. took me a few hours to nail it. the code is:
for (int i = 0; i < list.Count-1; i++) {
list[i+1].DoSomeThing();
//some code
if (someCondition) {
list.insert(i+1, new Item());
i++;
}
}
at some point, the list[i+1]
is addressed as list[i]
, as if both both point to the same item.
this bug was so wierd. the code ran well at debug mode, and at release mode, but when I ran it out side visual studio, ex. from the .exe file, the code crashed. only turning off the compiler optimization fixed it.