110,546
社区成员
发帖
与我相关
我的任务
分享
using System;
class MyClass
{
Base b = new Base();
~MyClass()
{
Console.WriteLine("MyClasss的finalize函数");
Program.sBase = b; //<--复活Base
GC.ReRegisterForFinalize(b);
}
}
class Base
{
~Base()
{
Console.WriteLine("Base的finalize函数");
}
}
class Program
{
public static Base sBase;
static void Main(string[] args)
{
MyClass m = new MyClass();
m = null;
GC.Collect();
GC.WaitForPendingFinalizers();
Console.Read();
Program.sBase = null;
GC.Collect();
Console.Read();
}
}
class LibraryContainer : IContainer
{
private ArrayList m_bookList;
//...
//...
public virtual void Dispose()
{
for (int i = 0; i < m_bookList.Count; ++i)
{
IComponent curObj = (IComponent)m_bookList[i];
curObj.Dispose();
}
m_bookList.Clear();
}
}
public interface IComponent : IDisposable
{
ISite Site { get; set; }
event EventHandler Disposed;
}
public interface IContainer : IDisposable
{
ComponentCollection Components { get; }
void Add(IComponent component);
void Add(IComponent component, string name);
void Remove(IComponent component);
}