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;
}
}
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;
}
}