public void SetTemplate(T template, IObjectAllocator <T> allocator) { Clear(); if (_template != null) { _allocator.Destroy(_template); } _template = template; _allocator = allocator; _allocator.SetTemplate(_template); }
public void Recycle(T obj) { if (_list.Count > (uint)(MaxCache * 1.5f)) { _allocator.Destroy(obj); // var reduceCnt = (uint)(MaxCache * 0.5f); for (int i = 0; i < reduceCnt; i++) { var item = _list.Last.Value; _list.RemoveLast(); _allocator.Destroy(item); } } else { _allocator.OnRecycle(obj); _list.AddLast(obj); } }