anhngml / aforge

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

BlobCounter has memory leaks. #347

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
i don't know why.

This way everything works.

// blobs!
var bc = new BlobCounter {BackgroundThreshold = Color.FromArgb(254, 254, 254)};
Rectangle[] rects;
using (var tempClone = (Bitmap)temp.Clone()) // BlobCounter memory leaks.
{
 bc.ProcessImage(tempClone);
 rects = bc.GetObjectsRectangles();
}

This way - sometimes i get AccessViolation exceptions

var bc = new BlobCounter {BackgroundThreshold = Color.FromArgb(254, 254, 254)};
Rectangle[] rects = bc.ProcessImage(temp);
rects = bc.GetObjectsRectangles();

Code for creating image temp.

Bitmap temp = GrayScaleImageHelper.FromData(
                        _backgroundModel._width,
                        _backgroundModel._height,
                        _backgroundModel._stride,
                        foreground);

...
public static Bitmap FromData(int width, int height, int stride, byte[] data)
        {
            byte[,] dataHeightWidth;
            GCHandle handle;
            var result = BeginImage(width, height, out dataHeightWidth, out handle);
            for (int widthI = 0; widthI < width; widthI++)
            {
                for (int heightI = 0; heightI < height; heightI++)
                {
                    dataHeightWidth[heightI, widthI] = data[ToDataPosition(widthI, heightI, stride)];
                }
            }
            EndImage(handle);
            return result;
        }
...
public static void EndImage(GCHandle handle)
{
 handle.Free();
}

public static int ToDataPosition(int width, int height, int stride)
{
 return height*stride + width;
}

Original issue reported on code.google.com by cuchuk.s...@gmail.com on 10 Jun 2013 at 11:07

GoogleCodeExporter commented 9 years ago
The code provided does not really points to the issue. I've used the 
BlobCounter for about 5 years - never had an issue.

Try to create a very simple console base application which reproduces the 
issue. For now to me it looks like something is really going wrong in your app.

Original comment by andrew.k...@gmail.com on 18 Jun 2013 at 4:44