Reputation: 254
This question was asked by a lot but none answered!
I am using EmguCV, the OpenCV wrapper for .NET. I am disposing all created objects but my app is still using more and more memory till it crashes.
I nearly tried everything, including: .Dispose()
=null
using()
and even GC was running nearly every half a second, nothing did work!
Here's my code:
(I have selected 100 scanned images, all of JPG type and 300dpi) One of these images is uploaded to DropBox in order to preserve quality: https://www.dropbox.com/s/tsbe8pesbxk7dsz/Example.jpg?dl=0
private void OpenFolder_Click(object sender, EventArgs e)
{
using (OpenFileDialog open = new OpenFileDialog())
{
open.Multiselect = true;
if (open.ShowDialog() == DialogResult.OK)
for (int i = 0; i < open.FileNames.Count(); i++)
using (Image<Bgr, byte> ToProcess = new Image<Bgr, byte>(open.FileNames[i]))
ProcessImage (ToProcess);
}
}
private void ProcessImage (Image<Bgr, byte> imgInput)
{
imgInput._SmoothGaussian(5);
}
Also I tried to update the code inside ProcessImage
Function to the following, but my program freezes and crashes!
IntPtr image = imgInput;
imgInput._SmoothGaussian(5);
CvInvoke.cvReleaseImage(ref image);
Important Update: if the function finishes before my program crashes, surprisingly it will release All of the memory. Here is a graph.
I am using VS 2017-Community, Win10 64-bit, both up to date, and last stable version of EmguCV 3.4.3
Upvotes: 2
Views: 347