Arduino rebooting with Serial.println

I am running a program.

... some code here...
while (1)
   {
   delay(5000);
   Serial.println("while start");
   delay(5000);
   Serial.println("yes");
   delay(5000);
... some code here using digitalRead(g) etc

What is happening that the loop code runs fine for a couple of times and then reboots the Arduino. If I comment out Serial.println -lines all goes fine. I also tried Serial.flush() but it causes almost immediate. I also get corrupted output from above lines. Serial.println works fine otherwise in other programs. I believe it is some timing issue but delay above should take care of that.
I there another way to debug code other than using Serial.println?

newuser:
I believe it is some timing issue but delay above should take care of that.

I believe you have a memory issue in the code that you did not show. The Serial.println() is only the symptom of the disease :wink:

For us to help you to cure the disease, please provide the full code.