Why does these the application on the top does not throw a stack overflow exception ? what's up with the recursive method ? I understand that the bottom example creates a deep call stack so it throws the error. But the first example do we use the same space in the memory or does the garbage collector help us.
class ProgramErrorFree
{
static void Main()
{
while(true)
{
Console.WriteLine(Guid.NewGuid());
}
}
}
class ProgramStackOverFlow
{
static void Recursive(int value)
{
// Write call number and call this method again.
// ... The stack will eventually overflow.
Console.WriteLine(value);
Recursive(++value);
}
static void Main()
{
// Begin the infinite recursion.
Recursive(0);
}
}