Search Unity

Bug Dispose CPU resources

Discussion in 'Barracuda' started by ihabkhoury, Mar 11, 2021.

  1. ihabkhoury

    ihabkhoury

    Joined:
    Dec 16, 2020
    Posts:
    3
    Hi,
    I noticed that when I use barracuda worker with WorkerFactory.Type.CSharpBurst or WorkerFactory.Type.CSharp, calling Dispose() does not clean the memory correctly.

    Code (CSharp):
    1. var worker = WorkerFactory.CreateWorker(WorkerFactory.Type.CSharp, model);
    2. var inputTensor = new Tensor(texture, channelCount);  // [1, 320, 256, 3]
    3. worker.Execute(inputTensor);
    4. var output = worker.PeekOutput();
    5. ...
    6. inputTensor.Dispose();
    7. output.Dispose();
    8. worker.Dispose();
    Could you please advice?
    Thank you
     
  2. alexandreribard_unity

    alexandreribard_unity

    Unity Technologies

    Joined:
    Sep 18, 2019
    Posts:
    53
    Could you clarify a bit what you mean by `does not clean the memory correctly`?
    Did you notice memory leaks or high memory usage?
     
  3. ihabkhoury

    ihabkhoury

    Joined:
    Dec 16, 2020
    Posts:
    3
    Hello Alexandre,
    Correct! I noticed a memory leak.
    I have created an application that takes a photo, creates a Texture2D and the Tensor layer then passes it to the model to be classified. After getting the output I run dispose() as you can see, also I DestroyImmediate the Texture2D and I do System.GC.Collect().

    I added this: System.GC.GetTotalMemory(false) before and after the function and with each time the memory keeps going up and never clearen. After 5 times repeating the same process I get OutOfMemory error.

    Looking forward to hearing from you soon.
     
  4. alexandreribard_unity

    alexandreribard_unity

    Unity Technologies

    Joined:
    Sep 18, 2019
    Posts:
    53
    Ok thanks. What Barracuda version are you on?
     
  5. ihabkhoury

    ihabkhoury

    Joined:
    Dec 16, 2020
    Posts:
    3
    Hi,
    I'm using barracuda-release-1.3.0

    Thanks