1

I need to load around 70-100 images on datagridview (DatagridviewImageColumn) and I can do it but only loads 33 and then I get: "System out of memory exception" Memoria insuficiente.

The images have high resolution (1600x2700). My code is:

 If FolderBrowserDialog1.ShowDialog = DialogResult.OK Then
     For Each Documento As String In My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly)
         *Dim imagen As Image = Image.FromFile(Documento)
          DataGridView1.Rows(a).Cells(0).value = imagen
          a = a + 1
     Next
 End If

The error points to line with (*)

I also tried with delays (Threading.Thread.Sleep(3500)) and Through Timer with interval of 3500 but I still get the same error.

What can I do?

Thanks.

user3822492
  • 145
  • 1
  • 11
  • What is the Size property set to? How many rows are filled before the error occurs? – ron tornambe Apr 09 '16 at 17:47
  • The width and height of datagridview cells are 100 and the rows filled are 33 – user3822492 Apr 09 '16 at 19:17
  • 1
    If your application is 32-bit, it is limited to 1.6 GB of RAM. Do your images occupy that much space? – ron tornambe Apr 09 '16 at 19:48
  • Yes, I´m developing on VS2015 in a 32 bit machine and the images have a size about a 1.75 mb each one – user3822492 Apr 09 '16 at 22:37
  • That still does not add up to 1.6 GB. Can you build a 64-bit app? - even just to test this hypothesis. – ron tornambe Apr 09 '16 at 23:13
  • I dont have 64 bit equipment :P and nobody here its able to lend me. I tried to use thumbnails (100x100) but I get the same error. Is there a way to liberate memory or resources after assign the image to DGV cell? – user3822492 Apr 10 '16 at 03:28
  • No. I do not think so. Perhaps you have a memory leak somewhere? What else in your code could be taking up so much memory? – ron tornambe Apr 10 '16 at 03:39
  • I closed all other applications and by now there is no more than the code to add images to datagridview. Thanks anyway Ron. – user3822492 Apr 10 '16 at 03:57

1 Answers1

0

I found the answer.

Instead loading images to datagridview I used only their names and to process them instead using FOR I used a Timer and this lines:

  GC.Collect()
  GC.WaitForPendingFinalizers()

At the end of every iteration and that solve the problem.

user3822492
  • 145
  • 1
  • 11