AForge camera memory leak

后端 未结 3 964
遇见更好的自我
遇见更好的自我 2021-01-21 18:41

I\'m developing an application in C#, and I developed a library that does some stuff with Aforge cameras. One of the points is to simply capture images of what is i

3条回答
  •  独厮守ぢ
    2021-01-21 19:15

    AForge owns the bytes of the image, you should make your own deep copy. Passing the frame to the Bitmap constructor is not enough. If the framework is not able to properly dispose the bitmap because you have a reference to it, there's a leak.

    Try with this:

    private void NewFrame(object sender, NewFrameEventArgs args)
    {
        Bitmap newFrame = AForge.Imaging.Image.Clone(args.Frame);
        PictureBox.FromBitmapImage(newFrame);
        newFrame.Dispose();
    }
    

提交回复
热议问题