title: c# picturebox memory releasing problem
body: <p>I'm a newby in C#. I have to repeatedly refresh a GUI picture box in a worker thread. The image is acquired from a camera polling a driver with a GetImage method that retrives the image to be displayed. Even if I allocate the bitmap using directive "using" and explicitly call G.C, memory seems to be never deallocated. </p>
  
  <p>The worker thread is something like this: </p>
  
  <pre><code>   while (true)
      {
          // request image with IR signal values (array of UInt16)
          image = axLVCam.GetImage(0);
          lut = axLVCam.GetLUT(1);
          DrawPicture(image, lut);
          //GC.Collect();
  
      }
  </code></pre>
  
  <p>While the DrawPicture method is something like</p>
  
  <pre><code>   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 is ready - update image control
  
          //SetControlPropertyThreadSafe(tempTxtBox, "Text", string.Format("{0:0.#}", lutTempConversion[im[160, 100]]));
  
          //tempTxtBox.Text = string.Format("{0:00000}", im[160, 100]);
          //System.Drawing.Image.FromHbitmap(bmp.GetHbitmap());
          pic.Image = System.Drawing.Image.FromHbitmap(bmp.GetHbitmap());
      }
  }
  </code></pre>
  
  <p>Problems arises with the</p>
  
  <blockquote>
    <p>pic.Image = System.Drawing.Image.FromHbitmap(bmp.GetHbitmap());</p>
  </blockquote>
  
  <p>In fact commenting that line of code, garbage collection works as it would.
  Better, the problem seems to be with </p>
  
  <blockquote>
    <p>System.Drawing.Image.FromHbitmap(bmp.GetHbitmap())</p>
  </blockquote>
  
  <p>Any advice to solve this memory leak?</p>
  
  <p>Thanks a lot!</p>