2 using System.Collections.Generic;
8 readonly Func<T> _factoryMethod;
9 readonly Action<T> _resetMethod;
10 readonly Stack<T> _objectPool;
12 public ObjectPool(Func<T> factoryMethod, Action<T> resetMethod = null) {
13 _factoryMethod = factoryMethod;
14 _resetMethod = resetMethod;
15 _objectPool =
new Stack<T>();
19 return _objectPool.Count == 0
24 public void Push(T obj) {
25 if(_resetMethod != null) {
28 _objectPool.Push(obj);