cheap-memoryram

while(true) iteration runs out RAM memory


I am trying to figure out this issue: I tried to run this two easy codes

int main(void) {
    while(1) {
       printf("Do nothing\n");
    }
   return 0;
}

When I execute it my memory RAM runs out. Then I tried this variation:

int main(void) {
    while(1) {
       // do nothing
    }
   return 0;
}

And on that case my code runs without running out RAM. My question is: why does it happen? Does printf occupied memory or maybe I am overloading stdout? Thanks!


Solution

  • If the terminal that is running out of memory, then yes, the terminal isn't clearing the stdout properly.

    If it's the program itself running out of memory, then i don't know actually.