BalaShiyamala / opencvdotnet

Automatically exported from code.google.com/p/opencvdotnet
0 stars 0 forks source link

Memory leak in OpenCVDotNet #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Open OpenCVDotNet Example project
2. Run it, Choose MeanShift
3. Open any compatible video format and play, observe the task manager you
will see the memory gonna run out very fast. After 200 frames the system
could run out around 700Mb!!!

 (Compatible video format for opencv can be converted from any video file
by VirtualDub)

What version of the product are you using? On what operating system?
OpenCVDotNet 0.7 and OpenCV 1.0 and WindowsXP SP2

Please provide any additional information below.

This problem is really serious, i don't have much time to investigate
deeper into the OpenCVDotNet code base thus could not provide right
solution. It should be related to the Capture.QueryFrame() function where
resource is not well release for the garbage collector.

Original issue reported on code.google.com by lequoct...@gmail.com on 15 Oct 2007 at 2:29

GoogleCodeExporter commented 8 years ago
I guess you're in luck since I have just experienced a similar memory leak 
issue, 
which I have now identified the cause of. It's due to a misunderstanding on the 
author's part, in which he releases allocated memory in the destructors of the 
classes, which is incorrect in managed C++. It should instead be deallocated in 
a 
the finalizer method, declared similary to the destructor, but with a '!' 
instead of 
the '~'.

I have not fixed all the issues, but an example is in the cvimage.h, where I 
have 
replaced the destructor with the following:

virtual ~CVImage()
{
   this->!CVImage();
}

!CVImage()
{
   Release();
}

Search the library for any remaining destructors and fix it likewise.

Original comment by kanon...@gmail.com on 19 Oct 2007 at 12:27

GoogleCodeExporter commented 8 years ago
kanongil, I have the same problem,your solution is not working fine even when I
disposing CVImage

here my c# code:
            CVImage img; 
            unsafe
            {
                int depth = getDepth(frame.MIplImage.depth);
                sbyte* b = (;sbyte*)frame.MIplImage.imageData
                img = new CVImage(frame.MIplImage.width, frame.MIplImage.height,
depth, frame.MIplImage.nChannels, b);
                //MessageBox.Show("done");
            }
            img.Dispose();

I changed the code of c++ as u told me and rebuild the project but still 
leaking !

virtual ~CVImage()
{
   this->!CVImage();
}

!CVImage()
{
   Release();
}

Original comment by kdjd2...@gmail.com on 21 Dec 2008 at 6:15