Unmanage memory growth when calling Onnx from C# with C++ API #22992
Labels
api:CSharp
issues related to the C# API
.NET
Pull requests that update .net code
performance
issues related to performance regressions
Describe the issue
Hello, I have an application written in dotnet that is calling a managed C++ class which in turn wraps Native C++ code containing the Onnx calls
On Startup the C# class is calling the Load Model function like so:
mImageInferencer.LoadModel(AppDomain.CurrentDomain.BaseDirectory + ModelPath, enableGpu, counter);
The Inferencer classes may have multiple instances created within Tasks in .Net
This initializes the ONNX Session like so:
Both the mOrtSession and onnxSessionEnv are class level variables
The .Net class then listens for new images passed to a message queue and, upon receiving an image, passes it to the model for processing like so:
int numDetections = mImageInferencer.ProcessImageV10(frame, frame.Length, (float)options.ConfidenceThreshold, options.EnableTracking, inputKey);
This is a process that runs infinitely so long as we receive frames from the source (cameras)
This process then calls the Session Run on the Onnx Session as below:
The problem is that we are seeing a constant growth in Unmanaged memory when running this process function, I have tried disabling CPU Arena and Mem Arena to no avail. Even Releasing and re-initializing the session does not help.
I have also run this with the TensorRT as well as CPU and am still seeing the unmanaged memory grow
To reproduce
Running model with the same Onnx session causes seemingly infinite growth in unmanaged memory
Urgency
Have an upcoming production deployment in a week that requires this fixed
Platform
Windows
OS Version
Windows Server 2019
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.18.0
ONNX Runtime API
C++
Architecture
X64
Execution Provider
CUDA, TensorRT
Execution Provider Library Version
No response
Model File
No response
Is this a quantized model?
No
The text was updated successfully, but these errors were encountered: