在开篇之前我盲猜一下,引用池出现的目的是为了可以手动控制一部分的 GC, 避免引用一直无法被回收的情况 ReferencePool 的代码不多,所以看起来会轻松一些
# IReference 接口
只有一个方法,清理引用
Clear ();
# ReferencePoolInfo 引用池信息类
非常好理解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| [StructLayout(LayoutKind.Auto)] public struct ReferencePoolInfo { private readonly Type m_Type; private readonly int m_UnusedReferenceCount; private readonly int m_UsingReferenceCount; private readonly int m_AcquireReferenceCount; private readonly int m_ReleaseReferenceCount; private readonly int m_AddReferenceCount; private readonly int m_RemoveReferenceCount;
public ReferencePoolInfo(Type type, int unusedReferenceCount, int usingReferenceCount, int acquireReferenceCount, int releaseReferenceCount, int addReferenceCount, int removeReferenceCount) { m_Type = type; m_UnusedReferenceCount = unusedReferenceCount; m_UsingReferenceCount = usingReferenceCount; m_AcquireReferenceCount = acquireReferenceCount; m_ReleaseReferenceCount = releaseReferenceCount; m_AddReferenceCount = addReferenceCount; m_RemoveReferenceCount = removeReferenceCount; }
public Type Type { get { return m_Type; } }
public int UnusedReferenceCount { get { return m_UnusedReferenceCount; } }
public int UsingReferenceCount { get { return m_UsingReferenceCount; } }
public int AcquireReferenceCount { get { return m_AcquireReferenceCount; } }
public int ReleaseReferenceCount { get { return m_ReleaseReferenceCount; } }
public int AddReferenceCount { get { return m_AddReferenceCount; } }
public int RemoveReferenceCount { get { return m_RemoveReferenceCount; } } }
|