I’m trying to load about 600 small images into memory. Size of each image file is less then 2 KB (20 x 30). Thus all images are needs at most 5 MB in memory, even with additional information about size, format etc.
But after 400th image Image.FromFile() throws OutOfMemory exception.
So, what’s the problem?
The
OutOfMemoryExceptionis a bit of a misnomer when you are dealing with theImage.FromFilemethod. The FromFile method will throw anOutOfMemoryExceptionin some cases where there is actually not an out of memory situation. NamelyDocumentation: http://msdn.microsoft.com/en-us/library/stf701f5.aspx
I think if you debug into this you’ll find it’s a very specific file which is causing this problem every time. Try removing that file from your list and see if it fixes your problem.