High CPU and Memory leaks in C#
| Required Info | |
|---|---|
| Camera Model | D400 |
| Firmware Version | 05.08.15.00 |
| Operating System & Version | Win10 |
| Platform | PC |
| SDK Version | 2.13.0 |
| Language | C# |
Issue Description
Question 1: When i open color stream and depth stream with pipeline function, the computer CPU > 90%.
This is a part of codes:
cfg.EnableStream(Stream.Depth, D_W, D_H, Format.Z16, 30);
cfg.EnableStream(Stream.Color, C_W, C_H, Format.Bgr8,30);
pipeline.Start(cfg);
Question 2: When i use "SpatialFilter" and "TemporalFilter", the computer memory will increase slowly. I also open this program one day, the memory >700MB.
This is a part of codes:
using (var f = Pipe.WaitForFrames() as FrameSet)
{
Align align = new Align(Stream.Color);
FrameSet _frames = align.Process(f);
//--------------Spatial Filter---------------
SpatialFilter Spat = new SpatialFilter();
Spat.Options[Option.FilterMagnitude].Value = 2.0f;
Spat.Options[Option.FilterSmoothAlpha].Value = 0.5f;
Spat.Options[Option.FilterSmoothDelta].Value = 20.0f;
Spat.Options[Option.HolesFill].Value = 2.0f;
var Spat_Depth = Spat.ApplyFilter(_frames.DepthFrame);
Spat.Dispose();
//-------------------------------------------
//--------------Temporal Filter---------------
TemporalFilter Tempor = new TemporalFilter();
Tempor.Options[Option.FilterSmoothAlpha].Value = 0.4f;
Tempor.Options[Option.FilterSmoothDelta].Value = 20.0f;
Tempor.Options[Option.HolesFill].Value = 4.0f;
var Tempor_Depth = Tempor.ApplyFilter(Spat_Depth);
Tempor.Dispose();
//-------------------------------------------
var Colorized_Depth = Colorize.Colorize(Tempor_Depth);
Tempor_Depth.Dispose();
}
In the release notes for the latest 2.14.0 SDK release, there is a Known issue that was identified about C# memory leaks:
C# query device function doesn't release memory, causing memory leak
Are you using the query device function in your full script in 2.13.0, please?
Also, the 2.14.0 release contains significant optimizations of the Align processing block. Would it be possible to try your program with the 2.14.0 SDK and see if you get improved performance?
@MartyG-RealSense Yes, the cpu problem is solved, cpu rate decrease 50%-60%. But the memory leak problem still alive.
There may be nothing that can be done about the memory leak until it is fixed in a future SDK update, regretfully. The Librealsense development team are good at finding and fixing memory leaks, though there is no way to apply a fix until it is released as part of a new SDK version.
@MartyG-RealSense This problem like #1983 . I really think about this problem is filter function. When i not to use it, memory not leak.
On that issue #1983 , SmirkingMan posted an update an hour ago before he closed the issue in which he concluded: "There seems to be an issue with memory allocation when creating and destroying filters / video frames. The issue can be circumvented by pre-allocating everything up front".
@MartyG-RealSense OK, thanks a lot. I hope this problem can be solve recently.
Hi @HungLearner
You should really avoid creating new Align, SpatialFilter or any other processing block inside the streaming loop. These translate to heavy native objects with a lot of internal state, that should be initialized once per device.
@dorodnic The memory is stable now, and i will also test a few day. Thanks for your help!