consultantscros.blogg.se

Java stack overflow error example
Java stack overflow error example




java stack overflow error example

Also mind that your stack space can run out of memory before reaching a valid terminating condition, thus make sure your method can handle input values requiring more recursive calls. If you have, then check that when calling the function you have at least modified one of the arguments, otherwise there'll be no visible change for the recursively called function and the terminating condition is useless. If you've got functions that call themselves then check that you've got a terminating condition. To deal with them, you'll need to examine your code. Here you've not explicitly called yourself, but the OS/VM has done it for you. For example, your app may be handling paint messages, and, whilst processing them, it may call a function that causes the system to send another paint message.

java stack overflow error example

However, with GUI programming, it's possible to generate indirect recursion. Or when the termination condition is fine, it can be caused by requiring too many recursive calls before fulfilling it. Typically, this is caused when your recursive functions doesn't have the correct termination condition, so it ends up calling itself forever. The common cause for a stack overflow is a bad recursive call. As you can see, there is a potential for the heap to "collide" with the stack (a bit like tectonic plates!!!). As you allocate memory, this heap can grow towards the upper end of your address space. Your process also has a heap, which lives at the bottom end of your process. The stack typically lives at the upper end of your address space and as it is used up it heads towards the bottom of the address space (i.e. Parameters and local variables are allocated on the stack (with reference types, the object lives on the heap and a variable in the stack references that object on the heap).






Java stack overflow error example