I have read several SO question/answers about this topic, however they made me even more confused. Here is the deal:
I have an application which reads many images from the disk. Even though I have enough RAM to read that much of bytes, I get System.OutOfMemoryException
while reading the data, even before start to process them.
Here is my reading process, basicly:
class Image
{
float[,] pixels;
}
public static void ReadImages()
{
List<Image> images = new List<Image>();
for(int i=0;i<length;i++)
{
Image image = ReadImageFromDisk(); // Reads image from the disk.
if ( Do I need this image? ) // Check whether to store on the memory or not
{
images.Add(image);
}
}
}
The reason I use List<Image>
is basicly I don't know how many Image
I am going to store in the memory. I am reading the Image
from the disk and then I decide whether to store that image on memory or not.
Making a basic memory calculation:
= 28 (image width) x 28 (image height) x 4 (float) x 500,000 (number of images)
= 1568000000 bytes = 1.568 Gigabyte
I am using 64bit Windows 7 and I have 16 Gigabytes of RAM installed. Why I am getting OutOfMemory
exception?