8.4 Automatic memory management

来源:互联网 发布:linux提权命令 编辑:程序博客网 时间:2024/06/10 01:20
8.4 Automatic memory management
Manual memory management requires developers to manage the allocation and
de-allocation of blocks of
memory. Manual memory management can be both time-consuming and difficult.
In C#, automatic memory
management is provided so that developers are freed from this burdensome
task. In the vast majority of
cases, automatic memory management increases code quality and enhances
developer productivity without
negatively impacting either expressiveness or performance.
The example
using System;
public class Stack
{
private Node first = null;
public bool Empty {
get {
return (first == null);
}
}
public object Pop() {
if (first == null)
throw new Exception("Can’t Pop from an empty Stack.");
else {
object temp = first.Value;
first = first.Next;
return temp;
}
}
原创粉丝点击