Java Stack Overflow Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss how to solve stack overflow error in java the workings and policies of this site About Us Learn more about how to resolve stack overflow error in java Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow
Java Increase Stack Size
Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each
Stackoverflowerror Java Recursion
other. Join them; it only takes a minute: Sign up What is a StackOverflowError? up vote 221 down vote favorite 74 What is a StackOverflowError, what causes it, and how should I deal with them? java exception-handling stack-overflow share|improve this question edited Jun 19 '15 at 4:55 asked Oct 18 '08 at 8:13 Ziggy 7,384165475 add a comment| fix stack overflow error 11 Answers 11 active oldest votes up vote 230 down vote accepted Parameters and local variables are allocated on the stack (with reference types the object lives on the heap and a variable references that object). 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. towards zero). Your process also has a heap, which lives at the bottom end of your process. As you allocate memory this heap can grow towards the upper end of your address space. As you can see, there is the potential for the heap to "collide" with the stack (a bit like tectonic plates!!!). The common cause for a stack overflow is a bad recursive call. Typically this is caused when your recursive functions doesn't have the correct termination condition, so it ends up calling itself forever. However, with GUI programming it's possible to generate indirect recursion. For example, your app may be handling paint messages and whilst proc
Method java.lang Class StackOverflowError java.lang.Object java.lang.Throwable stack overflow error in c java.lang.Error java.lang.VirtualMachineError java.lang.StackOverflowError All Implemented Interfaces: Serializable public class StackOverflowError extends VirtualMachineError Thrown http://stackoverflow.com/questions/214741/what-is-a-stackoverflowerror when a stack overflow occurs because an application recurses too deeply. Since: JDK1.0 See Also:Serialized Form Constructor Summary Constructors Constructor and Description StackOverflowError() Constructs https://docs.oracle.com/javase/7/docs/api/java/lang/StackOverflowError.html a StackOverflowError with no detail message. StackOverflowError(Strings) Constructs a StackOverflowError with the specified detail message. Method Summary Methods inherited from classjava.lang.Throwable addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString Methods inherited from classjava.lang.Object clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, <
My Publications Saturday, July 4, 2009 Diagnosing and Resolving StackOverflowError A recent JavaWorld Community forum message (Stack Overflow after instantiating new object) reminded me that the basics of the StackOverflowError are not always understood well http://marxsoftware.blogspot.com/2009/07/diagnosing-and-resolving.html by people new to Java. Fortunately, the StackOverflowError is one of the easier of the runtime errors to debug and in this blog posting I will demonstrate how easy it often is to diagnose a StackOverflowError. Note that the potential for stack overflow is not limited to Java.Diagnosing the cause of a StackOverflowError can be fairly straightfoward if the code has been compiled with stack overflow the debug option turned on so that line numbers are available in the resulting stack trace. In such cases, it is typically simply a matter of finding the repeating pattern of line numbers in the stack trace. The pattern of repeating line numbers is helpful because a StackOverflowError is often caused by unterminated recursion. The repeating line numbers indicate the code that is being stack overflow error directly or indirectly recursively called. Note that there are situations other than unbounded recursion in which a stack overflow might occur, but this blog posting is limited to StackOverflowError caused by unbounded recursion.The relationship of recursion gone bad to StackOverflowError is noted in the Javadoc description for StackOverflowError that states that this Error is "Thrown when a stack overflow occurs because an application recurses too deeply." It is significant that StackOverflowError ends with the word Error and is an Error (extends java.lang.Error via java.lang.VirtualMachineError) rather than a checked or runtime Exception. The difference is significant. The Error and Exception are each a specialized Throwable, but their intended handling is quite different. The Java Tutorial points out that Errors are typically external to the Java application and thus normally cannot and should not be caught or handled by the application.I will demonstrate running into StackOverflowError via unbounded recursion with three different examples. The code used for these examples is contained in three classes, the first of which (and the main class) is shown next. I list all three classes in their entirety because line numbers are significant when debugging the St