docs.unity.cn
    Show / Hide Table of Contents

    Class ObjectPool<T>

    Provides a generic object pool implementation.

    Inheritance
    Object
    ObjectPool<T>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Unity.XR.CoreUtils
    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.

    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Tuesday, July 18, 2023