A process is a method or it can be other things? Can you give me an example of stack overflow error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

A process is a method or it can be other things? Can you give me an example of stack overflow error?

When a process starts, it get a default stack size which is fixed for each process. Under abnormal condition, the stack limit exceeds. This is know as stack overflow.

5th Feb 2020, 11:36 AM
Hichem GOUIA
Hichem GOUIA - avatar
4 Answers
+ 3
Hichem GOUIA Infinite loop is not necessarily an stack overflow error. If you don't create new variables each time the loop runs, then no memory gets used up. So it can run for ever, without an error. Infinite recursion is necessarily an stack overflow error. During a function call, some memory is allocated to store the parameters, return address, etc. During infinite recursion, all the stack memory gets exhausted and thus the JVM gives the error. I Stack Overflow mostly occurs in cases as shown by my code. But it can occur in other cases where the stack memory is used up. Another example is, one class calling the constructor of other class and the other class calls the constructor of the first class. (When both the objects depend on each other). This can also produce the error. (It is similar to recursion. but it's two constructors calling each other infinitely) If you declare too many local variables which take up stack memory, this can also happen.
6th Feb 2020, 4:11 AM
Tejaswi Hegde
Tejaswi Hegde - avatar
+ 4
Stack overflow is caused by something which takes up all of the stack memory. Here is an example of an stack overflow error which is caused by a recursive function. I catch the Error and print it. https://code.sololearn.com/c6Rn3wMu38z9/#java
5th Feb 2020, 12:54 PM
Tejaswi Hegde
Tejaswi Hegde - avatar
0
Tejaswi Hegde infinite loop is it an example of stack overflow error?
5th Feb 2020, 10:15 PM
Hichem GOUIA
Hichem GOUIA - avatar
0
Well explained my friend 😊 Thanks a lot
6th Feb 2020, 9:40 AM
Hichem GOUIA
Hichem GOUIA - avatar