5.9.08

Sample code for Garbage Collector [GC] in C#.Net

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
public class Base
{
~Base()
{
Console.WriteLine(“Base Finalizer called”);
}
}

public class Derived : Base
{
~Derived()
{
Console.WriteLine(“Derived Finalizer called”);
}

public void Suppress()
{
GC.SuppressFinalize(this);
}
}

class Program
{
static void Main(string[] args)
{
Derived d = new Derived();
d.Suppress();
Console.ReadLine();
}
}
}

No comments: