GC.Collect() Issues when Disposing Inputs/Outputs

Hi everyone,

I’m currently having a GC issue with a model I am working with. I’m working off of this github Unity Project GitHub - adcimon/mocap-vfx: Unity project of 3D pose estimation with VFX using Barracuda and VFX Graph. which is a fork of GitHub - digital-standard/ThreeDPoseUnityBarracuda: Unity sample of 3D pose estimation using Barracuda project.

When running the project from github on Unity ver. 2020.2.1f1 and Barracuda ver. 1.0.4, it works perfectly - no massive GC stutters. But when I port the code over to the LTS of Unity with the latest Barracuda, I get massive spikes from GC.Collect().

I tried using 1.0.4 ver. of Barracuda, but it didn’t make a difference. And after looking through the code (which can be found on either github) BarracudaRunner.cs it seems like all outputs are being disposed of correctly (maybe I’m wrong here). However, I’m not sure if the inputs could be causing this issue, as only one is disposed of every update(), but I don’t think this would be the issue as they are being replaced every update()

private void UpdateAvatar()
{
    input = new Tensor(videoCapture.renderTexture);
    if (inputs[inputName1] == null)
    {
        inputs[inputName1] = input;
        inputs[inputName2] = new Tensor(videoCapture.renderTexture);
        inputs[inputName3] = new Tensor(videoCapture.renderTexture);
    }
    else
    {
        inputs[inputName3].Dispose();

        inputs[inputName3] = inputs[inputName2];
        inputs[inputName2] = inputs[inputName1];
        inputs[inputName1] = input;
    }

    StartCoroutine(ExecuteModel());
}

I think it might be that something changed in how the GC works from Unity version 2020.1->2022 but I’m not sure what, as I’m only starting out learning Barracuda/Unity.

It also could because of this:

private IEnumerator Load()
{
    inputs[inputName1] = new Tensor(baseTexture);
    inputs[inputName2] = new Tensor(baseTexture);
    inputs[inputName3] = new Tensor(baseTexture);

    // Create input and execute model.
    yield return worker.StartManualSchedule(inputs);
    Debug.Log("Count:" + model.outputs.Count);
    // Get outputs.
    for (int i = 2; i < model.outputs.Count; i++)
    {
        outputs[i] = worker.PeekOutput(model.outputs[i]);
    }

    // Get data from outputs.
    offset3D = outputs[2].data.Download(outputs[2].shape);
    heatMap3D = outputs[3].data.Download(outputs[3].shape);
    Debug.Log(outputs.Length);
    // Release outputs.
    for (int i = 2; i < outputs.Length; i++)
    {
        outputs[i].Dispose();
    }

    PredictPose();

    yield return new WaitForSeconds(waitTime);

    videoCapture.Initialize(inputImageSize, inputImageSize);

    loaded = true;
}

I’m referring to the data.download function…

Apologies if this is formatted horribly, any help would be appreciated

  • C

So, what ended up fixing the issue was changing the Burst package to 1.3.4, which was the one used in the github projects linked above. Something must have changed, just no sure what… any insight on this would be great (:

I’m possibly using depreciated functions.

1 Like