Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why doesn't a forever loop crash? Why does an infinite recursion crash?

My question is: Why does an infinite recursion crash, but not an infinite loop? They both feel like normal forever iterators yet one crashes while the other doesn’t. I am looking for the hardware/low-level response. I usually get stackoverflow error when experimenting this on Jupyter with Python. Also, when I mean low-level response, I mean what happens in the computer hardware(RAM, CPU) that causes the infinite recursion to crash, but not the infinite iteration.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Because an infinite recursion keep storing recursive calls in the stack (which is one of the memories held by your application), so it will eventually fill the stack completely, hence you get the classic stack overflow error.

In an infinite loop, you don’t store anything and frequently you just keep updating variables and things like that, which won’t occupy more memory than they these variables already do, so nothing will break. However, you can have an infinite loop breaking if you add things in the memory inside your loop, like adding an element to a list inside the loop.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading