PooledObject.cs 693 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. namespace UnityEditor.Graphing
  3. {
  4. class PooledObject<T> : IDisposable where T : new()
  5. {
  6. private ObjectPool<T> m_ObjectPool;
  7. public T value { get; private set; }
  8. internal PooledObject(ObjectPool<T> objectPool, T value)
  9. {
  10. m_ObjectPool = objectPool;
  11. this.value = value;
  12. }
  13. private void ReleaseUnmanagedResources()
  14. {
  15. m_ObjectPool.Release(value);
  16. }
  17. public void Dispose()
  18. {
  19. ReleaseUnmanagedResources();
  20. GC.SuppressFinalize(this);
  21. }
  22. ~PooledObject()
  23. {
  24. ReleaseUnmanagedResources();
  25. }
  26. }
  27. }