Reputation: 104
May be my question is irrelevant, it will probably may never happened as stack has 1MB of memory.
But if stack memory becomes full, what will happen. Because garbage collector will not perform cleaning for stack.
Upvotes: 2
Views: 1395
Reputation: 62120
When the stack fills up, you get a StackOverflowException
exception.
Of course the stack may fill up, if your code has a bug which causes runaway recursion, or if you use recursion to implement an algorithm which is unsuitable for recursion, like for example linear search.
You can very easily check what happens with runaway recursion like this:
static void Main( string[] args )
{
Main( args );
}
Upvotes: 2
Reputation: 50692
It is quite easy to overflow the stack:
int* ptr = stackalloc int[4000000];
A StackOverflowException will occur.
Upvotes: 2
Reputation: 2272
I'm definitely not an expert, but my guess would be a StackOverflowException
.
I don't think you'll ever fill the whole 1MB stack though.
Upvotes: 1