Ask Your Question

Revision history [back]

Hello! I am using openCV with .Net C# wrapper. On Windows 10 when I load the cascade xml I use it multiple times in a loop and after that I dispose() the object, which releases its resources. But when i load and dispose multiple times at different stages of my application, I have noticed that it doesn't releases all the memory. Execute this peace of code multiple times and you will start seeing memory increase. The odd thing is that when I run the same code on Linux machine under the mono environment the memory stays the fairly the same. I am 101% sure that i dispose all the images which are used in the process. My code looks something like this:

CascadeClassifier cascadeClassifier = new CascadeClassifier(resourceManager.FRONTAL_FACE_ALT_PATH);  
Rectangle localR = new Rectangle();
while (isWindowOpen && !faceFound)
   {
       Mat localImage;                    

       localImage = new Mat(workingImage, new Rectangle(new Point(0, 0), workingImage.Size));
       CvInvoke.CvtColor(localImage, localImage, ColorConversion.Bgr2Gray);
       workingImage.Dispose();
       CvInvoke.EqualizeHist(localImage, localImage);
       Rectangle[] faces = cascadeClassifier.DetectMultiScale(localImage, 1.1, 10, Size.Empty);                
       localImage.Dispose();                    

       Thread.Sleep(20);
   }
cascadeClassifier.Dispose();