复制代码 代码如下:
Object obj = new Object();
WeakReference wref = new WeakReference( obj );
obj = null;
复制代码 代码如下:
Object obj2 = wref.Target;
if( obj2 != null )
{
// 做你想做的事吧。
}
else
{
// 对象已经被回收,如果要用必须新建一个。
}
复制代码 代码如下:
// public WeakReference(
// object target,
// bool trackResurrection
//);
Object obj1 = new Object();
Object obj2 = new Object();
WeakReference wref1 = new WeakReference( obj1, false );
WeakReference wref2 = new WeakReference( obj2, true );
复制代码 代码如下:
public class AspPage : Page
{
private static ArrayList __ENCList = new ArrayList();
[DebuggerNonUserCode]
public AspPage()
{
base.Load += new EventHandler(this.Page_Load);
ArrayList list = __ENCList;
lock (list)
{
__ENCList.Add(new WeakReference(this));
}
}
}
新闻热点
疑难解答
图片精选