Why does a recursive function stop on random numbers?2019 Community Moderator ElectionWhat is a StackOverflowError?Why does Java have transient fields?Changing main parameter typeWhy does this code using random strings print “hello world”?Is it possible to write a program in Java without main() using JDK 1.7 or higher?Size of String array passed as argument to main method in EclipseWhy the main method should be in staticJava - Method executed prior to Default ConstructorHello,How can i add two panels in one frame?When use java regular-expression pattern.matcher(), source does not match regex.But, my hope result is ,source matches regexWould it make any difference giving arguments using scanner class instead of command line arguments?

How strictly should I take "Candidates must be local"?

How did Alan Turing break the enigma code using the hint given by the lady in the bar?

Is it necessary to separate DC power cables and data cables?

Intuition behind counterexample of Euler's sum of powers conjecture

What Happens when Passenger Refuses to Fly Boeing 737 Max?

An alternative proof of an application of Hahn-Banach

What problems would a superhuman have whose skin is constantly hot?

Are all players supposed to be able to see each others' character sheets?

Dropdown com clique

Conservation of Mass and Energy

Are tamper resistant receptacles really safer?

Reverse string, can I make it faster?

Word for a person who has no opinion about whether god exists

They call me Inspector Morse

UART pins to unpowered MCU?

Can you reject a postdoc offer after the PI has paid a large sum for flights/accommodation for your visit?

Declaring and defining template, and specialising them

Should I tell my boss the work he did was worthless

Filtering SOQL results with optional conditionals

'The literal of type int is out of range' con número enteros pequeños (2 dígitos)

If I receive an SOS signal, what is the proper response?

List elements digit difference sort

Signed and unsigned numbers

Distinction between apt-cache and dpkg -l



Why does a recursive function stop on random numbers?



2019 Community Moderator ElectionWhat is a StackOverflowError?Why does Java have transient fields?Changing main parameter typeWhy does this code using random strings print “hello world”?Is it possible to write a program in Java without main() using JDK 1.7 or higher?Size of String array passed as argument to main method in EclipseWhy the main method should be in staticJava - Method executed prior to Default ConstructorHello,How can i add two panels in one frame?When use java regular-expression pattern.matcher(), source does not match regex.But, my hope result is ,source matches regexWould it make any difference giving arguments using scanner class instead of command line arguments?










7















I wrote a small program shown below that counts how many times an infinite recursive loop will go before causing a StackOverflow error.



public class Testing 
static void p(int i)
System.out.println("hello" + i);
i++;
p(i);

public static void main(String[] args)
p(1);




The thing is, it errors on a different number each time, normally between 8000 and 9000. Can anyone explain why this happens?



EDIT: I'm using the Eclipse IDE, haven't tested it with other IDE's or the command line.










share|improve this question
























  • Do this number changes if setting stack size using -Xss command line parameter?

    – cesarse
    9 hours ago











  • It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

    – Joakim Danielson
    8 hours ago















7















I wrote a small program shown below that counts how many times an infinite recursive loop will go before causing a StackOverflow error.



public class Testing 
static void p(int i)
System.out.println("hello" + i);
i++;
p(i);

public static void main(String[] args)
p(1);




The thing is, it errors on a different number each time, normally between 8000 and 9000. Can anyone explain why this happens?



EDIT: I'm using the Eclipse IDE, haven't tested it with other IDE's or the command line.










share|improve this question
























  • Do this number changes if setting stack size using -Xss command line parameter?

    – cesarse
    9 hours ago











  • It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

    – Joakim Danielson
    8 hours ago













7












7








7








I wrote a small program shown below that counts how many times an infinite recursive loop will go before causing a StackOverflow error.



public class Testing 
static void p(int i)
System.out.println("hello" + i);
i++;
p(i);

public static void main(String[] args)
p(1);




The thing is, it errors on a different number each time, normally between 8000 and 9000. Can anyone explain why this happens?



EDIT: I'm using the Eclipse IDE, haven't tested it with other IDE's or the command line.










share|improve this question
















I wrote a small program shown below that counts how many times an infinite recursive loop will go before causing a StackOverflow error.



public class Testing 
static void p(int i)
System.out.println("hello" + i);
i++;
p(i);

public static void main(String[] args)
p(1);




The thing is, it errors on a different number each time, normally between 8000 and 9000. Can anyone explain why this happens?



EDIT: I'm using the Eclipse IDE, haven't tested it with other IDE's or the command line.







java recursion






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 8 hours ago







AfterShock360

















asked 9 hours ago









AfterShock360AfterShock360

587




587












  • Do this number changes if setting stack size using -Xss command line parameter?

    – cesarse
    9 hours ago











  • It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

    – Joakim Danielson
    8 hours ago

















  • Do this number changes if setting stack size using -Xss command line parameter?

    – cesarse
    9 hours ago











  • It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

    – Joakim Danielson
    8 hours ago
















Do this number changes if setting stack size using -Xss command line parameter?

– cesarse
9 hours ago





Do this number changes if setting stack size using -Xss command line parameter?

– cesarse
9 hours ago













It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

– Joakim Danielson
8 hours ago





It looks like the exception happens during println and the string handling, could it depend on how/when garbage collection occurs?

– Joakim Danielson
8 hours ago












5 Answers
5






active

oldest

votes


















3














The JVM specs very nicely explain its behavior related to stack;




Each Java Virtual Machine thread has a private Java Virtual Machine
stack, created at the same time as the thread. A Java Virtual Machine
stack stores frames (§2.6). A Java Virtual Machine stack is analogous
to the stack of a conventional language such as C: it holds local
variables and partial results, and plays a part in method invocation
and return. Because the Java Virtual Machine stack is never
manipulated directly except to push and pop frames, frames may be heap
allocated. The memory for a Java Virtual Machine stack does not need
to be contiguous.



In the First Edition of The Java® Virtual Machine Specification, the
Java Virtual Machine stack was known as the Java stack.



This specification permits Java Virtual Machine stacks either to be of
a fixed size or to dynamically expand and contract as required by the
computation. If the Java Virtual Machine stacks are of a fixed size,
the size of each Java Virtual Machine stack may be chosen
independently when that stack is created.



A Java Virtual Machine implementation may provide the programmer or
the user control over the initial size of Java Virtual Machine stacks,
as well as, in the case of dynamically expanding or contracting Java
Virtual Machine stacks, control over the maximum and minimum sizes.



The following exceptional conditions are associated with Java Virtual
Machine stacks:



If the computation in a thread requires a larger Java Virtual Machine
stack than is permitted, the Java Virtual Machine throws a
StackOverflowError.



If Java Virtual Machine stacks can be dynamically expanded, and
expansion is attempted but insufficient memory can be made available
to effect the expansion, or if insufficient memory can be made
available to create the initial Java Virtual Machine stack for a new
thread, the Java Virtual Machine throws an OutOfMemoryError.




An important point from this excerpt as far as your question is concerned:



  • This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation.

Since you are not providing a stack size, JVM tries to dynamically expand the stack size as the function gets called recursively needing more stack memory. In each run, it may find different amount of dynamic memory for its stack depending on the availability of memory on your computer at that point of run. This is the reason you see a different value for the number of iterations it takes before throwing the SO error. If you configure (using Xss<size> JVM parameter) a smaller stack size to your program, you should see mostly identical number of recursions before the SO error.






share|improve this answer






























    1














    Might be related to how much real memory the computer can allocate to the program, while other programs and process are running in the computer






    share|improve this answer






























      1














      StackOverflowError is a error. As a error, is related to the JVM (a error is not a Exception!).



      This error occurs when your stack (or method execution stack) collides with your heap size (JVM's memory).



      The size of JVM's heap can be defined, but from your stack no.






      share|improve this answer






























        1














        So as others have pointed out you may have to look into what jvm is beings used and from there it might also be a good exercise to know what garbage collector (how often gc is being called ) is being used as this may give you a deeper understanding not only about stack overflow error but how generally Java works. And if really keen you could implement your own small JVM and may be with a better scheme.






        share|improve this answer






























          0














          StackOverflowError is thrown, when stack (part of memory, where method execution stack is stored) collides with heap (memory, that allocates objects, primitives etc.). You cannot predict, when the error is thrown, because the size of stack can be dynamic unless specified by -Xss flag. That's why there is no fixed method execution depth, that causes StackOverflowError.






          share|improve this answer

























          • This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

            – David Soroko
            8 hours ago











          • @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

            – Andronicus
            8 hours ago











          • Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

            – David Soroko
            6 hours ago












          • @DavidSoroko edited

            – Andronicus
            6 hours ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55108159%2fwhy-does-a-recursive-function-stop-on-random-numbers%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          The JVM specs very nicely explain its behavior related to stack;




          Each Java Virtual Machine thread has a private Java Virtual Machine
          stack, created at the same time as the thread. A Java Virtual Machine
          stack stores frames (§2.6). A Java Virtual Machine stack is analogous
          to the stack of a conventional language such as C: it holds local
          variables and partial results, and plays a part in method invocation
          and return. Because the Java Virtual Machine stack is never
          manipulated directly except to push and pop frames, frames may be heap
          allocated. The memory for a Java Virtual Machine stack does not need
          to be contiguous.



          In the First Edition of The Java® Virtual Machine Specification, the
          Java Virtual Machine stack was known as the Java stack.



          This specification permits Java Virtual Machine stacks either to be of
          a fixed size or to dynamically expand and contract as required by the
          computation. If the Java Virtual Machine stacks are of a fixed size,
          the size of each Java Virtual Machine stack may be chosen
          independently when that stack is created.



          A Java Virtual Machine implementation may provide the programmer or
          the user control over the initial size of Java Virtual Machine stacks,
          as well as, in the case of dynamically expanding or contracting Java
          Virtual Machine stacks, control over the maximum and minimum sizes.



          The following exceptional conditions are associated with Java Virtual
          Machine stacks:



          If the computation in a thread requires a larger Java Virtual Machine
          stack than is permitted, the Java Virtual Machine throws a
          StackOverflowError.



          If Java Virtual Machine stacks can be dynamically expanded, and
          expansion is attempted but insufficient memory can be made available
          to effect the expansion, or if insufficient memory can be made
          available to create the initial Java Virtual Machine stack for a new
          thread, the Java Virtual Machine throws an OutOfMemoryError.




          An important point from this excerpt as far as your question is concerned:



          • This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation.

          Since you are not providing a stack size, JVM tries to dynamically expand the stack size as the function gets called recursively needing more stack memory. In each run, it may find different amount of dynamic memory for its stack depending on the availability of memory on your computer at that point of run. This is the reason you see a different value for the number of iterations it takes before throwing the SO error. If you configure (using Xss<size> JVM parameter) a smaller stack size to your program, you should see mostly identical number of recursions before the SO error.






          share|improve this answer



























            3














            The JVM specs very nicely explain its behavior related to stack;




            Each Java Virtual Machine thread has a private Java Virtual Machine
            stack, created at the same time as the thread. A Java Virtual Machine
            stack stores frames (§2.6). A Java Virtual Machine stack is analogous
            to the stack of a conventional language such as C: it holds local
            variables and partial results, and plays a part in method invocation
            and return. Because the Java Virtual Machine stack is never
            manipulated directly except to push and pop frames, frames may be heap
            allocated. The memory for a Java Virtual Machine stack does not need
            to be contiguous.



            In the First Edition of The Java® Virtual Machine Specification, the
            Java Virtual Machine stack was known as the Java stack.



            This specification permits Java Virtual Machine stacks either to be of
            a fixed size or to dynamically expand and contract as required by the
            computation. If the Java Virtual Machine stacks are of a fixed size,
            the size of each Java Virtual Machine stack may be chosen
            independently when that stack is created.



            A Java Virtual Machine implementation may provide the programmer or
            the user control over the initial size of Java Virtual Machine stacks,
            as well as, in the case of dynamically expanding or contracting Java
            Virtual Machine stacks, control over the maximum and minimum sizes.



            The following exceptional conditions are associated with Java Virtual
            Machine stacks:



            If the computation in a thread requires a larger Java Virtual Machine
            stack than is permitted, the Java Virtual Machine throws a
            StackOverflowError.



            If Java Virtual Machine stacks can be dynamically expanded, and
            expansion is attempted but insufficient memory can be made available
            to effect the expansion, or if insufficient memory can be made
            available to create the initial Java Virtual Machine stack for a new
            thread, the Java Virtual Machine throws an OutOfMemoryError.




            An important point from this excerpt as far as your question is concerned:



            • This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation.

            Since you are not providing a stack size, JVM tries to dynamically expand the stack size as the function gets called recursively needing more stack memory. In each run, it may find different amount of dynamic memory for its stack depending on the availability of memory on your computer at that point of run. This is the reason you see a different value for the number of iterations it takes before throwing the SO error. If you configure (using Xss<size> JVM parameter) a smaller stack size to your program, you should see mostly identical number of recursions before the SO error.






            share|improve this answer

























              3












              3








              3







              The JVM specs very nicely explain its behavior related to stack;




              Each Java Virtual Machine thread has a private Java Virtual Machine
              stack, created at the same time as the thread. A Java Virtual Machine
              stack stores frames (§2.6). A Java Virtual Machine stack is analogous
              to the stack of a conventional language such as C: it holds local
              variables and partial results, and plays a part in method invocation
              and return. Because the Java Virtual Machine stack is never
              manipulated directly except to push and pop frames, frames may be heap
              allocated. The memory for a Java Virtual Machine stack does not need
              to be contiguous.



              In the First Edition of The Java® Virtual Machine Specification, the
              Java Virtual Machine stack was known as the Java stack.



              This specification permits Java Virtual Machine stacks either to be of
              a fixed size or to dynamically expand and contract as required by the
              computation. If the Java Virtual Machine stacks are of a fixed size,
              the size of each Java Virtual Machine stack may be chosen
              independently when that stack is created.



              A Java Virtual Machine implementation may provide the programmer or
              the user control over the initial size of Java Virtual Machine stacks,
              as well as, in the case of dynamically expanding or contracting Java
              Virtual Machine stacks, control over the maximum and minimum sizes.



              The following exceptional conditions are associated with Java Virtual
              Machine stacks:



              If the computation in a thread requires a larger Java Virtual Machine
              stack than is permitted, the Java Virtual Machine throws a
              StackOverflowError.



              If Java Virtual Machine stacks can be dynamically expanded, and
              expansion is attempted but insufficient memory can be made available
              to effect the expansion, or if insufficient memory can be made
              available to create the initial Java Virtual Machine stack for a new
              thread, the Java Virtual Machine throws an OutOfMemoryError.




              An important point from this excerpt as far as your question is concerned:



              • This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation.

              Since you are not providing a stack size, JVM tries to dynamically expand the stack size as the function gets called recursively needing more stack memory. In each run, it may find different amount of dynamic memory for its stack depending on the availability of memory on your computer at that point of run. This is the reason you see a different value for the number of iterations it takes before throwing the SO error. If you configure (using Xss<size> JVM parameter) a smaller stack size to your program, you should see mostly identical number of recursions before the SO error.






              share|improve this answer













              The JVM specs very nicely explain its behavior related to stack;




              Each Java Virtual Machine thread has a private Java Virtual Machine
              stack, created at the same time as the thread. A Java Virtual Machine
              stack stores frames (§2.6). A Java Virtual Machine stack is analogous
              to the stack of a conventional language such as C: it holds local
              variables and partial results, and plays a part in method invocation
              and return. Because the Java Virtual Machine stack is never
              manipulated directly except to push and pop frames, frames may be heap
              allocated. The memory for a Java Virtual Machine stack does not need
              to be contiguous.



              In the First Edition of The Java® Virtual Machine Specification, the
              Java Virtual Machine stack was known as the Java stack.



              This specification permits Java Virtual Machine stacks either to be of
              a fixed size or to dynamically expand and contract as required by the
              computation. If the Java Virtual Machine stacks are of a fixed size,
              the size of each Java Virtual Machine stack may be chosen
              independently when that stack is created.



              A Java Virtual Machine implementation may provide the programmer or
              the user control over the initial size of Java Virtual Machine stacks,
              as well as, in the case of dynamically expanding or contracting Java
              Virtual Machine stacks, control over the maximum and minimum sizes.



              The following exceptional conditions are associated with Java Virtual
              Machine stacks:



              If the computation in a thread requires a larger Java Virtual Machine
              stack than is permitted, the Java Virtual Machine throws a
              StackOverflowError.



              If Java Virtual Machine stacks can be dynamically expanded, and
              expansion is attempted but insufficient memory can be made available
              to effect the expansion, or if insufficient memory can be made
              available to create the initial Java Virtual Machine stack for a new
              thread, the Java Virtual Machine throws an OutOfMemoryError.




              An important point from this excerpt as far as your question is concerned:



              • This specification permits Java Virtual Machine stacks either to be of a fixed size or to dynamically expand and contract as required by the computation.

              Since you are not providing a stack size, JVM tries to dynamically expand the stack size as the function gets called recursively needing more stack memory. In each run, it may find different amount of dynamic memory for its stack depending on the availability of memory on your computer at that point of run. This is the reason you see a different value for the number of iterations it takes before throwing the SO error. If you configure (using Xss<size> JVM parameter) a smaller stack size to your program, you should see mostly identical number of recursions before the SO error.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 8 hours ago









              VHSVHS

              7,02931028




              7,02931028























                  1














                  Might be related to how much real memory the computer can allocate to the program, while other programs and process are running in the computer






                  share|improve this answer



























                    1














                    Might be related to how much real memory the computer can allocate to the program, while other programs and process are running in the computer






                    share|improve this answer

























                      1












                      1








                      1







                      Might be related to how much real memory the computer can allocate to the program, while other programs and process are running in the computer






                      share|improve this answer













                      Might be related to how much real memory the computer can allocate to the program, while other programs and process are running in the computer







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 9 hours ago









                      riorioriorio

                      1,90031134




                      1,90031134





















                          1














                          StackOverflowError is a error. As a error, is related to the JVM (a error is not a Exception!).



                          This error occurs when your stack (or method execution stack) collides with your heap size (JVM's memory).



                          The size of JVM's heap can be defined, but from your stack no.






                          share|improve this answer



























                            1














                            StackOverflowError is a error. As a error, is related to the JVM (a error is not a Exception!).



                            This error occurs when your stack (or method execution stack) collides with your heap size (JVM's memory).



                            The size of JVM's heap can be defined, but from your stack no.






                            share|improve this answer

























                              1












                              1








                              1







                              StackOverflowError is a error. As a error, is related to the JVM (a error is not a Exception!).



                              This error occurs when your stack (or method execution stack) collides with your heap size (JVM's memory).



                              The size of JVM's heap can be defined, but from your stack no.






                              share|improve this answer













                              StackOverflowError is a error. As a error, is related to the JVM (a error is not a Exception!).



                              This error occurs when your stack (or method execution stack) collides with your heap size (JVM's memory).



                              The size of JVM's heap can be defined, but from your stack no.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 8 hours ago









                              DoYaThingDoYaThing

                              606




                              606





















                                  1














                                  So as others have pointed out you may have to look into what jvm is beings used and from there it might also be a good exercise to know what garbage collector (how often gc is being called ) is being used as this may give you a deeper understanding not only about stack overflow error but how generally Java works. And if really keen you could implement your own small JVM and may be with a better scheme.






                                  share|improve this answer



























                                    1














                                    So as others have pointed out you may have to look into what jvm is beings used and from there it might also be a good exercise to know what garbage collector (how often gc is being called ) is being used as this may give you a deeper understanding not only about stack overflow error but how generally Java works. And if really keen you could implement your own small JVM and may be with a better scheme.






                                    share|improve this answer

























                                      1












                                      1








                                      1







                                      So as others have pointed out you may have to look into what jvm is beings used and from there it might also be a good exercise to know what garbage collector (how often gc is being called ) is being used as this may give you a deeper understanding not only about stack overflow error but how generally Java works. And if really keen you could implement your own small JVM and may be with a better scheme.






                                      share|improve this answer













                                      So as others have pointed out you may have to look into what jvm is beings used and from there it might also be a good exercise to know what garbage collector (how often gc is being called ) is being used as this may give you a deeper understanding not only about stack overflow error but how generally Java works. And if really keen you could implement your own small JVM and may be with a better scheme.







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 8 hours ago









                                      briantaurostack7briantaurostack7

                                      2911726




                                      2911726





















                                          0














                                          StackOverflowError is thrown, when stack (part of memory, where method execution stack is stored) collides with heap (memory, that allocates objects, primitives etc.). You cannot predict, when the error is thrown, because the size of stack can be dynamic unless specified by -Xss flag. That's why there is no fixed method execution depth, that causes StackOverflowError.






                                          share|improve this answer

























                                          • This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                            – David Soroko
                                            8 hours ago











                                          • @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                            – Andronicus
                                            8 hours ago











                                          • Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                            – David Soroko
                                            6 hours ago












                                          • @DavidSoroko edited

                                            – Andronicus
                                            6 hours ago















                                          0














                                          StackOverflowError is thrown, when stack (part of memory, where method execution stack is stored) collides with heap (memory, that allocates objects, primitives etc.). You cannot predict, when the error is thrown, because the size of stack can be dynamic unless specified by -Xss flag. That's why there is no fixed method execution depth, that causes StackOverflowError.






                                          share|improve this answer

























                                          • This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                            – David Soroko
                                            8 hours ago











                                          • @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                            – Andronicus
                                            8 hours ago











                                          • Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                            – David Soroko
                                            6 hours ago












                                          • @DavidSoroko edited

                                            – Andronicus
                                            6 hours ago













                                          0












                                          0








                                          0







                                          StackOverflowError is thrown, when stack (part of memory, where method execution stack is stored) collides with heap (memory, that allocates objects, primitives etc.). You cannot predict, when the error is thrown, because the size of stack can be dynamic unless specified by -Xss flag. That's why there is no fixed method execution depth, that causes StackOverflowError.






                                          share|improve this answer















                                          StackOverflowError is thrown, when stack (part of memory, where method execution stack is stored) collides with heap (memory, that allocates objects, primitives etc.). You cannot predict, when the error is thrown, because the size of stack can be dynamic unless specified by -Xss flag. That's why there is no fixed method execution depth, that causes StackOverflowError.







                                          share|improve this answer














                                          share|improve this answer



                                          share|improve this answer








                                          edited 6 hours ago

























                                          answered 9 hours ago









                                          AndronicusAndronicus

                                          4,36121430




                                          4,36121430












                                          • This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                            – David Soroko
                                            8 hours ago











                                          • @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                            – Andronicus
                                            8 hours ago











                                          • Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                            – David Soroko
                                            6 hours ago












                                          • @DavidSoroko edited

                                            – Andronicus
                                            6 hours ago

















                                          • This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                            – David Soroko
                                            8 hours ago











                                          • @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                            – Andronicus
                                            8 hours ago











                                          • Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                            – David Soroko
                                            6 hours ago












                                          • @DavidSoroko edited

                                            – Andronicus
                                            6 hours ago
















                                          This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                          – David Soroko
                                          8 hours ago





                                          This is quite wrong, nothing collides with anything. The OP's program runs out of stack space which which has a default value and can be explicitly set ising the -Xss command line option

                                          – David Soroko
                                          8 hours ago













                                          @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                          – Andronicus
                                          8 hours ago





                                          @DavidSoroko here is a smilar explanation: stackoverflow.com/questions/214741/what-is-a-stackoverflowerror. However Op didn't set stack size

                                          – Andronicus
                                          8 hours ago













                                          Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                          – David Soroko
                                          6 hours ago






                                          Without referring to other answers on SO, can you explain what "stack collides with heap" actually means? After reading the documentation on -Xss here docs.oracle.com/javase/8/docs/technotes/tools/windows/java.html - please revisit your "You cannot predict..." remark.

                                          – David Soroko
                                          6 hours ago














                                          @DavidSoroko edited

                                          – Andronicus
                                          6 hours ago





                                          @DavidSoroko edited

                                          – Andronicus
                                          6 hours ago

















                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Stack Overflow!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55108159%2fwhy-does-a-recursive-function-stop-on-random-numbers%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          -java, recursion

                                          Popular posts from this blog

                                          Mobil Contents History Mobil brands Former Mobil brands Lukoil transaction Mobil UK Mobil Australia Mobil New Zealand Mobil Greece Mobil in Japan Mobil in Canada Mobil Egypt See also References External links Navigation menuwww.mobil.com"Mobil Corporation"the original"Our Houston campus""Business & Finance: Socony-Vacuum Corp.""Popular Mechanics""Lubrite Technologies""Exxon Mobil campus 'clearly happening'""Toledo Blade - Google News Archive Search""The Lion and the Moose - How 2 Executives Pulled off the Biggest Merger Ever""ExxonMobil Press Release""Lubricants""Archived copy"the original"Mobil 1™ and Mobil Super™ motor oil and synthetic motor oil - Mobil™ Motor Oils""Mobil Delvac""Mobil Industrial website""The State of Competition in Gasoline Marketing: The Effects of Refiner Operations at Retail""Mobil Travel Guide to become Forbes Travel Guide""Hotel Rankings: Forbes Merges with Mobil"the original"Jamieson oil industry history""Mobil news""Caltex pumps for control""Watchdog blocks Caltex bid""Exxon Mobil sells service station network""Mobil Oil New Zealand Limited is New Zealand's oldest oil company, with predecessor companies having first established a presence in the country in 1896""ExxonMobil subsidiaries have a business history in New Zealand stretching back more than 120 years. We are involved in petroleum refining and distribution and the marketing of fuels, lubricants and chemical products""Archived copy"the original"Exxon Mobil to Sell Its Japanese Arm for $3.9 Billion""Gas station merger will end Esso and Mobil's long run in Japan""Esso moves to affiliate itself with PC Optimum, no longer Aeroplan, in loyalty point switch""Mobil brand of gas stations to launch in Canada after deal for 213 Loblaws-owned locations""Mobil Nears Completion of Rebranding 200 Loblaw Gas Stations""Learn about ExxonMobil's operations in Egypt""Petrol and Diesel Service Stations in Egypt - Mobil"Official websiteExxon Mobil corporate websiteMobil Industrial official websiteeeeeeeeDA04275022275790-40000 0001 0860 5061n82045453134887257134887257

                                          Frič See also Navigation menuinternal link

                                          Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant