1

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"?

3
  • Can you paste some of the code of the loop? Did you use new[] or just new? Commented Aug 9, 2015 at 23:26
  • Code, code, code, please... Commented Aug 9, 2015 at 23:48
  • A crash on delete is almost certainly caused by an out-of-bounds write somewhere. Other than that, it is really difficult to comment without seeing some actual code. Is it not possible to reduce the amount of code and/or include the important bits here? Commented Aug 10, 2015 at 3:13

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.