An unhandled exception of type systemstackoverflowexception occurred in mscorlibdll
You might be intrested in what caused to produce Stack Overflow error. Here I will explain it with infinite looping
of functino using Recursion. This happens when there is no memory to to allocate function on Stack.
The memory used for stack is very limited and it varies from program to program.
When program tries to access the memory beond the stack that is buffer overflow known as stack overflow.
There are two types of program which can cause the stack overflow
1. The Recursino which never breaks the condition of going out.
2. A variable which is very large to allocate on Stack.
Code:
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int counter = RecursionDemo(0);
}
public static int RecursionDemo(int i)
{
i++;
return RecursionDemo(i);
}
}
}
Result
Another example at runtime.
Exception of type 'System.OutOfMemoryException' was thrown.
static void Main(string[] args)
{
int[] arr = new int[500000000];
}
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5