zoukankan      html  css  js  c++  java
  • [转]泛型弱引用

    public class WeakReference<T> : IDisposable
    {
    private GCHandle handle;
    private bool trackResurrection;

    public WeakReference(T target) : this(target, false) { }

    public WeakReference(T target, bool trackResurrection)
    {
    this.trackResurrection = trackResurrection;
    this.Target = target;
    }

    ~WeakReference()
    {
    Dispose();
    }

    public void Dispose()
    {
    handle.Free();
    GC.SuppressFinalize(
    this);
    }

    public virtual bool IsAlive
    {
    get { return (handle.Target != null); }
    }

    public virtual bool TrackResurrection
    {
    get { return this.trackResurrection; }
    }

    public virtual T Target
    {
    get
    {
    object o = handle.Target;
    if ((o == null) || (!(o is T)))
    return default(T);
    else
    return (T)o;
    }
    set
    {
    handle
    = GCHandle.Alloc(value, this.trackResurrection ? GCHandleType.WeakTrackResurrection : GCHandleType.Weak);
    }
    }
    }
  • 相关阅读:
    费马小定理
    CF 1365D Solve The Maze
    CF 1367D Task On The Board
    CF 1368B Codeforces Subsequences
    CF 1368C Even Picture
    mybatis框架
    Ajax
    jdbc
    jQuery
    JSP
  • 原文地址:https://www.cnblogs.com/Googler/p/1755523.html
Copyright © 2011-2022 走看看