Class ObjectPool<T>
Provides a generic object pool implementation.
Inherited Members
Namespace: Unity.XR.CoreUtils
Assembly: Unity.XR.CoreUtils.dll
Syntax
public class ObjectPool<T> where T : class, new()
Type Parameters
| Name | Description |
|---|---|
| T | The Type of objects in this pool. |
Fields
PooledQueue
All objects currently in this pool.
Declaration
protected readonly Queue<T> PooledQueue
Field Value
| Type | Description |
|---|---|
| Queue<T> |
Methods
ClearInstance(T)
Implement this function in a derived class to automatically clear an instance when Recycle(T) is called.
Declaration
protected virtual void ClearInstance(T instance)
Parameters
| Type | Name | Description |
|---|---|---|
| T | instance | The object to clear. |
Get()
Gets an object instance from the pool. Creates a new instance if the pool is empty.
Declaration
public virtual T Get()
Returns
| Type | Description |
|---|---|
| T | The object instance |
Recycle(T)
Returns an object instance to the pool.
Declaration
public void Recycle(T instance)
Parameters
| Type | Name | Description |
|---|---|---|
| T | instance | The instance to return. |
Remarks
Object values can be cleared automatically if ClearInstance(T) is implemented.
The base ObjectPool class does not clear objects to the pool.