7

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 (in release configuration too). I have debugged my app using .NET Memory profiler and get this result:

http://img532.imageshack.us/img532/2503/screenqv.png

all objects instance count is oscilating but GChandle instance counr is increasing until my machine is unusable. Garbage collector does not release memory (i think).

I am using VS 2008 professional, Win7 prof 32-bit, both up to date, and last stable version of emguCV.

I can post some app code, if it will help.

Thanks and sorry for my English. Martin

Martin Pilch
  • 3,245
  • 3
  • 38
  • 61
  • 1
    OpenCV is very nasty when it comes to disposing of objects. I would say you most likely are not disposing of something that should be disposed of. Put up some code and maybe we can find your error. – ubiquibacon May 16 '10 at 23:11

2 Answers2

1

Have a look at the link below on how to do Automatic Garbage Collection.
http://www.emgu.com/wiki/index.php/Working_with_Images
I had a similar problem and I started to improve my code using the different guidelines on the link above.
Regards
Shivam

Shivam
  • 144
  • 2
  • 9
  • Well it doesn't say much. Only that you either need to dispose manually(for example with `using`) or wait for the GC. And that Disposing is better. – CodesInChaos Feb 21 '11 at 11:26
  • Thanks, it is an obvious answer. Image Capture at 100ms over an hour... Thanks. – Rusty Nail Sep 05 '13 at 07:13
0
public static class IImageExtensions
{
    // http://stackoverflow.com/questions/20825497/difference-between-using-and-dispose-call-in-c-sharp 
    public static void FreeMem(this IImage image)
    {
        using (image)
        {
            using (image.Bitmap)
            {

            }
        }
        //image.Bitmap.Dispose();
        //image.Dispose();
    }
}
Andreas
  • 3,843
  • 3
  • 40
  • 53