title: Loading images to DataTable Out of Memory Exception
body: <p>I want to display images in my XtraGrid (devexpress control). before I display the grid, I want to load the data into a datatable. unfortunately, I always get an "out of memory exception" during loading the images. I only use small images (300 kb). I figured out, that the exception only occurs, when I am in release mode.</p>
  
  <p>here my code:</p>
  
  <pre><code>private void LoadData(List&lt;string&gt; categories)
      {
          SqlCeConnection cn;
  
          cn = new SqlCeConnection(ConnectionString);
  
          if (cn.State == ConnectionState.Closed)
          {
              cn.Open();
          }
  
          for (int j = 0; j &lt; categories.Count; j++)
          {
              string value = categories[j];
  
              // only if the connection string is not empty and a connection to the database was possible
              if (ConnectionString != string.Empty)
              {
                  if (value == "Alle")
                  {
                      DataTable dtAlle = new DataTable("Alle");
  
                      for (int i = 0; i &lt; data.Count; i++)
                      {
                          dtAlle.Merge(data[i], false, MissingSchemaAction.Add);
                      }
  
                      this.data.Add(dtAlle);
                  }
                  else
                  {
                      string sql = "select * from " + value;
  
                      SqlCeCommand cmd = new SqlCeCommand(sql, cn);
                      SqlCeDataAdapter da = new SqlCeDataAdapter(cmd);
                      DataTable dt = new DataTable(value);
                      da.Fill(dt);
  
                      List&lt;string&gt; imagePaths = new List&lt;string&gt;();
  
                      for (int i = 0; i &lt; dt.Rows.Count; i++)
                      {
                          imagePaths.Add(Convert.ToString(dt.Rows[i][0]));
                      }
  
                      dt.Columns.RemoveAt(0);
                      DataColumn col = new DataColumn("Vorschaubild", typeof(Image));
                      dt.Columns.Add(col);
                      dt.Columns["Vorschaubild"].SetOrdinal(0); // einfuegen an erster Stelle
  
                      for (int i = 0; i &lt; dt.Rows.Count; i++)
                      {
                          string imagePath = imagePaths[i];
                          if (imagePath != string.Empty)
                          {
                              FileInfo info = new FileInfo(imagePath);
                              string generatedPath = CheckIfPictureIsInClipboarPathAvailable(clipboardPath, info.Name);
  
                              if (generatedPath != string.Empty)
                              {
                                  using (Image image = Image.FromFile(generatedPath))
                                  {
                                      dt.Rows[i].SetField("Vorschaubild", image);
                                      image.Dispose();
                                  }
                              }
                              else if (imagePath != string.Empty)
                              {
                                  using (Image image = Image.FromFile(imagePath))
                                  {
                                      dt.Rows[i].SetField("Vorschaubild", image);
                                      image.Dispose();
                                  }
                              }
                          }
                      }
  
                      this.data.Add(dt);
                  }
              }
          }
      }
  </code></pre>
  
  <p>any suggestions?
  thanks,
  tro</p>