@@ -20,13 +20,15 @@ internal sealed partial class ObjectPoolManager : GameFrameworkModule, IObjectPo
20
20
private const int DefaultPriority = 0 ;
21
21
22
22
private readonly Dictionary < TypeNamePair , ObjectPoolBase > m_ObjectPools ;
23
+ private readonly List < ObjectPoolBase > m_CachedAllObjectPools ;
23
24
24
25
/// <summary>
25
26
/// 初始化对象池管理器的新实例。
26
27
/// </summary>
27
28
public ObjectPoolManager ( )
28
29
{
29
30
m_ObjectPools = new Dictionary < TypeNamePair , ObjectPoolBase > ( ) ;
31
+ m_CachedAllObjectPools = new List < ObjectPoolBase > ( ) ;
30
32
}
31
33
32
34
/// <summary>
@@ -76,6 +78,7 @@ internal override void Shutdown()
76
78
}
77
79
78
80
m_ObjectPools . Clear ( ) ;
81
+ m_CachedAllObjectPools . Clear ( ) ;
79
82
}
80
83
81
84
/// <summary>
@@ -1206,8 +1209,8 @@ public bool DestroyObjectPool(ObjectPoolBase objectPool)
1206
1209
/// </summary>
1207
1210
public void Release ( )
1208
1211
{
1209
- ObjectPoolBase [ ] objectPools = GetAllObjectPools ( true ) ;
1210
- foreach ( ObjectPoolBase objectPool in objectPools )
1212
+ GetAllObjectPools ( true , m_CachedAllObjectPools ) ;
1213
+ foreach ( ObjectPoolBase objectPool in m_CachedAllObjectPools )
1211
1214
{
1212
1215
objectPool . Release ( ) ;
1213
1216
}
@@ -1218,8 +1221,8 @@ public void Release()
1218
1221
/// </summary>
1219
1222
public void ReleaseAllUnused ( )
1220
1223
{
1221
- ObjectPoolBase [ ] objectPools = GetAllObjectPools ( true ) ;
1222
- foreach ( ObjectPoolBase objectPool in objectPools )
1224
+ GetAllObjectPools ( true , m_CachedAllObjectPools ) ;
1225
+ foreach ( ObjectPoolBase objectPool in m_CachedAllObjectPools )
1223
1226
{
1224
1227
objectPool . ReleaseAllUnused ( ) ;
1225
1228
}
0 commit comments