docs.unity3d.com
    Show / Hide Table of Contents

    Class ObjectPool<T>

    Instance pool for objects

    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 object to manage instances of

    Fields

    PooledQueue

    All objects in the pool

    Declaration
    protected readonly Queue<T> PooledQueue
    Field Value
    Type Description
    Queue<T>

    Methods

    ClearInstance(T)

    Implement a clearing function in this in a derived class to have the Recycle(T) method automatically clear the item.

    Declaration
    protected virtual void ClearInstance(T instance)
    Parameters
    Type Name Description
    T instance

    The object to return to the pool

    Get()

    Get an instance of the object type

    Declaration
    public virtual T Get()
    Returns
    Type Description
    T

    The object instance

    Recycle(T)

    Return an object instance to the pool

    Declaration
    public void Recycle(T instance)
    Parameters
    Type Name Description
    T instance

    The instance to return

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023