docs.unity3d.com
    Show / Hide Table of Contents

    Class MemoryTracker

    Generic service to manage shared objects and track the number of references to an object.

    Inheritance
    Object
    MemoryTracker
    Namespace: UnityEngine.Reflect
    Syntax
    public class MemoryTracker

    Constructors

    MemoryTracker(Clock.Proxy)

    Declaration
    public MemoryTracker(Clock.Proxy clock)
    Parameters
    Type Name Description
    Clock.Proxy clock

    Methods

    Acquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)

    Increment the reference count on the specific resource without returning the actual resource. This is useful in some scenario where the tracking count does not directly depend on the caller having the resource directly in its hands

    Declaration
    public void Acquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    Type Parameters
    Name Description
    TKey
    TValue

    AddAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)

    Add an item to the cache and increment the reference counter by 1.

    Declaration
    public void AddAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    TValue value
    Type Parameters
    Name Description
    TKey
    TValue

    ClearInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)

    Declaration
    public void ClearInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    Type Parameters
    Name Description
    TKey
    TValue

    ClearInactiveItemsOlderThan<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TimeSpan)

    Declaration
    public void ClearInactiveItemsOlderThan<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TimeSpan expirationTime)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TimeSpan expirationTime
    Type Parameters
    Name Description
    TKey
    TValue

    ContainsKey<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)

    Declaration
    public bool ContainsKey<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    TKey
    TValue

    CreateCache<TKey, TValue>(Action<TValue>)

    Creates a key/value cache.

    Declaration
    public MemoryTracker.Handle<TKey, TValue> CreateCache<TKey, TValue>(Action<TValue> destructorFunc)
        where TValue : class
    Parameters
    Type Name Description
    Action<TValue> destructorFunc

    The function called when the item is removed from the cache.

    Returns
    Type Description
    MemoryTracker.Handle<TKey, TValue>

    A handle to access the cache.

    Type Parameters
    Name Description
    TKey

    The key type.

    TValue

    The value type.

    DestroyCache<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)

    Destroy a key/value cache. Destroying a cache will call the destructor function received when the cache was created for each object in the cache, no matter if there are still active references on them.

    Declaration
    public void DestroyCache<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    Type Parameters
    Name Description
    TKey
    TValue

    GetActiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)

    Declaration
    public List<TValue> GetActiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    Returns
    Type Description
    List<TValue>
    Type Parameters
    Name Description
    TKey
    TValue

    GetInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)

    Declaration
    public List<TValue> GetInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    Returns
    Type Description
    List<TValue>
    Type Parameters
    Name Description
    TKey
    TValue

    Release<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)

    Release a reference to the object associated with the key. If the reference count drop to 0, the object is moved to a special buffer that can be cleared explicitly.

    Declaration
    public void Release<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    Type Parameters
    Name Description
    TKey
    TValue

    ReleaseAndDestroy<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)

    Declaration
    public void ReleaseAndDestroy<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    Type Parameters
    Name Description
    TKey
    TValue

    Set<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)

    Declaration
    public void Set<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    TValue value
    Type Parameters
    Name Description
    TKey
    TValue

    SetAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)

    Declaration
    public void SetAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    TValue value
    Type Parameters
    Name Description
    TKey
    TValue

    TryAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)

    Try to acquire a value in the cache from the key. WIll throw if the is invalid.

    Declaration
    public bool TryAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, out TValue value)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    TValue value
    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    TKey
    TValue

    TryGetValue<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)

    Tries to get a value from a key. This does not affect reference counting.

    Declaration
    public bool TryGetValue<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, out TValue value)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    TValue value
    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    TKey
    TValue

    TryRelease<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)

    Declaration
    public bool TryRelease<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
    Parameters
    Type Name Description
    MemoryTracker.Handle<TKey, TValue> handle
    TKey key
    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    TKey
    TValue
    In This Article
    • Constructors
      • MemoryTracker(Clock.Proxy)
    • Methods
      • Acquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
      • AddAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
      • ClearInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
      • ClearInactiveItemsOlderThan<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TimeSpan)
      • ContainsKey<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
      • CreateCache<TKey, TValue>(Action<TValue>)
      • DestroyCache<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
      • GetActiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
      • GetInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
      • Release<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
      • ReleaseAndDestroy<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
      • Set<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
      • SetAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
      • TryAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)
      • TryGetValue<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)
      • TryRelease<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
    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