// In 2021.1 this is part of Unity #if !UNITY_2021_1_OR_NEWER using System.Collections.Generic; namespace UnityEngine.Pool { internal class CollectionPool where TCollection : class, ICollection, new() { internal static readonly ObjectPool s_Pool = new ObjectPool(() => new TCollection(), null, l => l.Clear()); /// /// Get a new instance from the Pool. /// /// public static TCollection Get() => s_Pool.Get(); /// /// Get a new instance and a PooledObject. The PooledObject will automatically return the instance when it is Disposed. /// /// Output new instance. /// A new PooledObject. public static PooledObject Get(out TCollection value) => s_Pool.Get(out value); /// /// Release an object to the pool. /// /// instance to release. public static void Release(TCollection toRelease) => s_Pool.Release(toRelease); } internal class ListPool : CollectionPool, T> {} internal class HashSetPool : CollectionPool, T> {} internal class DictionaryPool : CollectionPool, KeyValuePair> {} } #endif