【发布时间】:2014-11-01 11:35:23
【问题描述】:
为什么这些顶部的应用程序不抛出堆栈溢出异常?递归方法是怎么回事?我知道底部示例创建了一个深层调用堆栈,因此它会引发错误。但是第一个例子是我们使用内存中的相同空间还是垃圾收集器帮助我们。
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);
}
}
【问题讨论】:
标签: c# memory-management garbage-collection