小编pic*_*cio的帖子

c#picturebox内存释放问题

我是C#的新手.我必须在工作线程中重复刷新GUI图片框.从使用GetImage方法轮询驱动程序的摄像机获取图像,该方法检索要显示的图像.即使我使用指令"using"分配位图并显式调用GC,内存似乎永远不会被释放.

工作线程是这样的:

   while (true)
    {
        // request image with IR signal values (array of UInt16)
        image = axLVCam.GetImage(0);
        lut = axLVCam.GetLUT(1);
        DrawPicture(image, lut);
        //GC.Collect();

    }
Run Code Online (Sandbox Code Playgroud)

虽然DrawPicture方法是类似的

   public void DrawPicture(object image, object lut)
{

  [...]

    // We have an image - cast it to proper type
    System.UInt16[,] im = image as System.UInt16[,];
    float[] lutTempConversion = lut as float[];

    int lngWidthIrImage = im.GetLength(0);
    int lngHeightIrImage = im.GetLength(1);

    using (Bitmap bmp = new Bitmap(lngWidthIrImage, lngHeightIrImage)) {

      [...many operation on bitmap pixel...]

        // Bitmap …
Run Code Online (Sandbox Code Playgroud)

c# memory-leaks memory-management picturebox

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

c# ×1

memory-leaks ×1

memory-management ×1

picturebox ×1