0

I'm a newbie in C# and Kinect. Currently, I'm working on a project which requires saving the incoming Kinect v2 frames into a local directory. I use the following codes to save the captured images. However, while I open the Task Manager during the program running, it seems that the occupied memory keeps rising up rapidly. Is there a way to lower the occupied memory?

a = SaveCombinedTimestamps.GetEnumerator();
        foreach (BitmapSource node in SaveCombinedFrames)
        {
            a.MoveNext();
            PngBitmapEncoder enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(node));
            string temppath = System.IO.Path.Combine(@"../test/color/", a.Current + ".png");
            using (System.IO.FileStream fs = new System.IO.FileStream(temppath, System.IO.FileMode.Create))
            {
                enc.Save(fs);
                fs.Close();
            }
        }
  • Then should I dispose of the enc after saving a new image? Since I guess the computer is supposed to release the memory for enc automatically. – AndyCai Mar 31 '20 at 19:20
  • Try to wrap your 'enc' variable in using statement, just like you are doing to your file stream. – Levko Ivanchuk Apr 01 '20 at 08:55
  • Sanity question here: if you completely remove all the code you posted but run the rest of the application, does memory keep rising up rapidly? In other words, are you **sure** that this block of code is what's making it "increasing the memory"? – Wyck Apr 02 '20 at 14:30
  • Are you [trying to find a leak](https://stackoverflow.com/questions/134086/what-strategies-and-tools-are-useful-for-finding-memory-leaks-in-net)? or is it just using more memory? Because obviously it will use more memory to encode than to just do nothing. How bad is it? – Wyck Apr 02 '20 at 14:38

0 Answers0