title: Out of memory exception while loading images
body: <p>I am using the following piece of code to load images as thumbnails to a FlowLayoutPanel control. Unfortunately  i get an OutOfMemory exception.</p>
  
  <p>As you already guess the memory leak is found at line </p>
  
  <pre><code> Pedit.Image = System.Drawing.Image.FromStream(fs)
  </code></pre>
  
  <p>So how could i optimize the following code?</p>
  
  <pre><code> Private Sub LoadImagesCommon(ByVal FlowPanel As FlowLayoutPanel, ByVal fi As FileInfo)
          Pedit = New DevExpress.XtraEditors.PictureEdit
          Pedit.Width = txtIconsWidth.EditValue
          Pedit.Height = Pedit.Width / (4 / 3)
          Dim fs As System.IO.FileStream
          fs = New System.IO.FileStream(fi.FullName, IO.FileMode.Open, IO.FileAccess.Read)
          Pedit.Image = System.Drawing.Image.FromStream(fs)
          fs.Close()
          fs.Dispose()
          Pedit.Properties.SizeMode = DevExpress.XtraEditors.Controls.PictureSizeMode.Zoom
  
          If FlowPanel Is flowR Then
              AddHandler Pedit.MouseClick, AddressOf Pedit_MouseClick
              AddHandler Pedit.MouseEnter, AddressOf Pedit_MouseEnter
              AddHandler Pedit.MouseLeave, AddressOf Pedit_MouseLeave
          End If
  
          FlowPanel.Controls.Add(Pedit)
      End Sub
  </code></pre>
  
  <p><strong>Update:</strong> The problem occurs while loading a number of images (3264x2448px at 300dpi - each image is about 3Mb's)</p>