Memory Leak in Astra.___Frame.CopyData(ref T[]) (2.0.16, AstraDotNet)

Playing around with SDK version 2.0.16, I think I may have discovered a pretty severe memory leak in the *.CopyData(ref type[]) functions, including:

  • DepthFrame.CopyData(ref short[])
  • ColorFrame.CopyData(ref byte[])
  • BodyMask.CopyData(ref byte[])

When just idly grabbing the data from the camera and copying it into arrays using the .CopyData functions, the application’s memory usage shoots up, hitting 5GB after less than 30s. I disabled everything else in the application, and the cause of the memory leak is definitely calling these functions.

Replacing depthFrame.CopyData(ref data) with Marshall.Copy(depthFrame.DataPtr, data, 0, data.Length) appears to eliminate the memory leak, with no noticeable loss of performance.

Am I doing something wrong with the .CopyData functions? e.g. is there something that implements the IDisposable interface that I should be disposing of? But they’re void functions with a simple array parameter, so there’s nothing obvious that I should dispose of.

I’d been struggling with this for the last two days and just found this question and workaround. Thanks, Chris! That seems to be solving my problems.