Skip to content

Commit

Permalink
优化GCAlloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiang Yin committed Nov 9, 2019
1 parent 9bd49e8 commit 52b3c78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions GameFramework/ObjectPool/ObjectPoolManager.ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ internal override void Shutdown()

m_Objects.Clear();
m_ObjectMap.Clear();
m_CachedCanReleaseObjects.Clear();
m_CachedToReleaseObjects.Clear();
}

private Object<T> GetObject(object target)
Expand Down
11 changes: 7 additions & 4 deletions GameFramework/ObjectPool/ObjectPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ internal sealed partial class ObjectPoolManager : GameFrameworkModule, IObjectPo
private const int DefaultPriority = 0;

private readonly Dictionary<TypeNamePair, ObjectPoolBase> m_ObjectPools;
private readonly List<ObjectPoolBase> m_CachedAllObjectPools;

/// <summary>
/// 初始化对象池管理器的新实例。
/// </summary>
public ObjectPoolManager()
{
m_ObjectPools = new Dictionary<TypeNamePair, ObjectPoolBase>();
m_CachedAllObjectPools = new List<ObjectPoolBase>();
}

/// <summary>
Expand Down Expand Up @@ -76,6 +78,7 @@ internal override void Shutdown()
}

m_ObjectPools.Clear();
m_CachedAllObjectPools.Clear();
}

/// <summary>
Expand Down Expand Up @@ -1206,8 +1209,8 @@ public bool DestroyObjectPool(ObjectPoolBase objectPool)
/// </summary>
public void Release()
{
ObjectPoolBase[] objectPools = GetAllObjectPools(true);
foreach (ObjectPoolBase objectPool in objectPools)
GetAllObjectPools(true, m_CachedAllObjectPools);
foreach (ObjectPoolBase objectPool in m_CachedAllObjectPools)
{
objectPool.Release();
}
Expand All @@ -1218,8 +1221,8 @@ public void Release()
/// </summary>
public void ReleaseAllUnused()
{
ObjectPoolBase[] objectPools = GetAllObjectPools(true);
foreach (ObjectPoolBase objectPool in objectPools)
GetAllObjectPools(true, m_CachedAllObjectPools);
foreach (ObjectPoolBase objectPool in m_CachedAllObjectPools)
{
objectPool.ReleaseAllUnused();
}
Expand Down

0 comments on commit 52b3c78

Please sign in to comment.