Reputation: 33
My IDE is Code::Blocks. I am in debug mode, I click on the "red play button" for Debug / Continue and my code runs fine. Then, always in debug mode, I click on the "green play button" for Run and my code crashes. Any ideas on why this happens? How can I find the bug in my code if clicking on Debug / Continue everything runs fine? I cannot include a copy of my code because it is too long.
After a trial and error debugging, I discovered that the program crashes when I use "delete[]" to deallocate the memory block pointed to by a pointer allocated with "new". Strange thing is that this dynamic allocation and deallocation is in a for loop, and the program crashes after a few loops, so not right at the beginning.
Thanks for any suggestions you may have.
EDIT: Allocation is with "new[]". I cannot paste the code because it is too long. The same allocation and deallocation is used in my code for other pointers without problems, but apparently only some of them cause the code to crash when deallocated. How can I debug if when I click on "Debug / Continue" the program does not crash but it crashes when I click on "Run"?
Upvotes: 1
Views: 1705
Reputation: 33
Thanks for your help. In the end my program was trying to access a pointer out of bounds, so I solved it. Weird thing is that the debugger did not show any error/warning (e.g. segmentation fault).
Upvotes: 0
Reputation: 1322
One major difference between debug and release modes is that often in debug, all memory will be initialized to zero. Often this makes things work better in debug than in release.
However, if you are accessing a pointer which has been initialized to 0, then this will cause a segmentation fault or similar. In release mode, you might just be lucky and have this pointer looking at memory that's accessible.
Upvotes: 1