docs.unity3d.com
    Show / Hide Table of Contents

    Manage memory

    As a Sentis user you are responsible for calling Dispose on any worker, inputs and sometimes outputs. You must call Dispose on outputs if you obtain them via worker.FinishExecutionAndDownloadOutput or if you take ownership of them by calling tensor.TakeOwnership.

    Note: Calling Dispose is necessary to properly free up GPU resources.

    For example:

    public void OnDestroy()
    {
        worker?.Dispose();
    
        // Assuming model with multiple inputs that were passed as a Dictionary
        foreach (var key in inputs.Keys)
        {
            inputs[key].Dispose();
        }
    
        inputs.Clear();
    }
    

    You don't need to call Dispose for the following:

    • Tensors that you receive via the worker.PeekOutput call.
    • CPUOps, GPUPixelOps, GPUComputeOps and GPUCommandBufferOps objects you create with no allocator.

    Additional resources

    • Profile a model
    • Create an engine to run a model
    • Create and modify tensors
    Back to top
    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