Unity Sentis creates memory leak in basic functions

Hello,

I’m working on integrating Unity Sentis into a project. While I’m only using basic features, I’ve encountered memory leaks in two specific functions within the Sentis library.

I’m wondering if this is an issue on Unity’s side or if there might be something incorrect in my implementation. Here’s the relevant code snippet, highlighting the lines that seem to be causing the leaks.

private void Update()
    {
        // This line
        TextureConverter.ToTensor(rawImage.texture, inputTensor, new TextureTransform());   
        
        if (!m_Started)
        {
            m_Schedule = worker.ScheduleIterable(inputTensor);
            m_Started = true;
        }
        
        int it = 0;
        while (m_Schedule.MoveNext())
        {
            if (++it % k_LayersPerFrame == 0)
                return;
        }
        
        // This line
        outputTensor = worker.PeekOutput() as Tensor<float>;
        
        cpuCopyTensor = outputTensor.ReadbackAndClone();
        m_Started = false;
        
        ProcessYoloOutput(cpuCopyTensor);
        
        cpuCopyTensor.Dispose();
        outputTensor.Dispose();
        inputTensor.Dispose();
    }

When I comment out these lines, the memory leak disappears. Also this problems seems only to be happening when I use GPUPixel as the backend type.

1 Like

So you see this only on the PixelBackend?
Compute doesn’t leak anything?

If so we’ll look into it

1 Like


In my project,TextureConverter.ToTensor() with PixelShader will causes memory leak,TextureConverter.ToTensor() with ComputeShader will not.

2 Likes