stack-overflow

Why does the count of calls of a recursive method causing a StackOverflowError vary between program runs? [duplicate]

扶醉桌前 提交于 2019-11-26 13:49:13
问题 This question already has an answer here: Why is the max recursion depth I can reach non-deterministic? 4 answers A simple class for demonstration purposes: public class Main { private static int counter = 0; public static void main(String[] args) { try { f(); } catch (StackOverflowError e) { System.out.println(counter); } } private static void f() { counter++; f(); } } I executed the above program 5 times, the results are: 22025 22117 15234 21993 21430 Why are the results different each time

Why I'm getting StackOverflowError

我的未来我决定 提交于 2019-11-26 12:48:24
问题 public class Category { private Category parentCategory; private Set<Category> childCategories; private String name; public Category() { childCategories = new HashSet<Category>(); } public Category getParentCategory() { return parentCategory; } public void setParentCategory(Category parentCategory) { this.parentCategory = parentCategory; } public Set<Category> getChildCategories() { return childCategories; } public void setChildCategories(Set<Category> childCategories) { this.childCategories

Why is the max recursion depth I can reach non-deterministic?

℡╲_俬逩灬. 提交于 2019-11-26 12:28:39
I decided to try a few experiments to see what I could discover about the size of stack frames, and how far through the stack the currently executing code was. There are two interesting questions we might investigate here: How many levels deep into the stack is the current code? How many levels of recursion can the current method reach before it hits a StackOverflowError ? Stack depth of currently executing code Here's the best I could come up with for this: public static int levelsDeep() { try { throw new SomeKindOfException(); } catch (SomeKindOfException e) { return e.getStackTrace().length

What is the difference between a segmentation fault and a stack overflow?

試著忘記壹切 提交于 2019-11-26 12:18:45
问题 For example when we call say, a recursive function, the successive calls are stored in the stack. However, due to an error if it goes on infinitely the error is \'Segmentation fault\' (as seen on GCC). Shouldn\'t it have been \'stack-overflow\'? What then is the basic difference between the two? Btw, an explanation would be more helpful than wikipedia links (gone through that, but no answer to specific query). 回答1: Stack overflow is [a] cause, segmentation fault is the result. At least on x86

Java regex to match start/end tags causes stack overflow

随声附和 提交于 2019-11-26 11:39:27
问题 The standard implementation of the Java Pattern class uses recursion to implement many forms of regular expressions (e.g., certain operators, alternation). This approach causes stack overflow issues with input strings that exceed a (relatively small) length, which may not even be more than 1,000 characters, depending on the regex involved. A typical example of this is the following regex using alternation to extract a possibly multiline element (named Data ) from a surrounding XML string,

Stack overflow caused by recursive function

醉酒当歌 提交于 2019-11-26 09:59:12
问题 Being a beginner to C++ programming and computer systems architecture, I\'m still learning the basics of C++. Yesterday I read about recursive function, so I decided to write my own, here\'s what I wrote : (very basic) int returnZero(int anyNumber) { if(anyNumber == 0) return 0; else { anyNumber--; return returnZero(anyNumber); } } And when I do this : int zero1 = returnZero(4793 ); it causes a stack overflow, however, if I pass the value 4792 as parameter, no overflow occurs. Any ideas as to

What actually causes a Stack Overflow error? [duplicate]

谁说胖子不能爱 提交于 2019-11-26 08:43:44
问题 This question already has an answer here: What is a StackOverflowError? 13 answers I\'ve looked everywhere and can\'t find a solid answer. According to the documentation, Java throws a java.lang.StackOverflowError error under the following circumstance: Thrown when a stack overflow occurs because an application recurses too deeply. But this raises two questions: Aren\'t there other ways for a stack overflow to occur, not only through recursion? Does the StackOverflowError happen before the

StackOverflowError when serializing an object in Java

旧巷老猫 提交于 2019-11-26 08:28:23
问题 I am writing an application in Java using Swing. I am trying to implement functionality to save and load simulation states for at simulation i am running. The entire simulation is kept as an object, disconnected from Swing. I am trying to serialize my Simulation class with this code: public void saveSimulationState(String simulationFile) { try { Serializable object = this.sm; ObjectOutputStream objstream = new ObjectOutputStream(new FileOutputStream(simulationFile)); objstream.writeObject

How to overcome Stack Size issue with Visual Studio (running C codes with big array)

二次信任 提交于 2019-11-26 06:45:07
问题 I am using Visual Studio 13 to compile c codes for the first time. The codes run perfectly O.K. with 2d arays of size 64*64 (there are a few arrays in my programme) but if I increase the array size to 128*128 it does not run (but compile correctly). Instead it gives a message \".exe has stopped working\". My machine has 4GB ram and the same programme run with 128*128 array if I run the codes from linux. Let me provide some more details: I have run the same code from linux using Intel C

What causes a java.lang.StackOverflowError

丶灬走出姿态 提交于 2019-11-26 05:56:10
问题 What can cause a java.lang.StackOverflowError ? The stack printout that I get is not very deep at all (only 5 methods). 回答1: Check for any recusive calls for methods. Mainly it is caused when there is recursive call for a method. A simple example is public static void main(String... args) { Main main = new Main(); main.testMethod(1); } public void testMethod(int i) { testMethod(i); System.out.println(i); } Here the System.out.println(i); will be repeatedly pushed to stack when the testMethod