I'm writing a simple image resizing program. By dragging multiple files onto the .exe, it will go through and resize each file. It works up to a certain point where an OOM (out of memory) exception is being thrown. I've tried calling Dispose on the bitmap and setting it to Null, but neither seems to do anything.
Bitmap current_image;
for (int i = 0; i < imagesfilepath.Count; ++i)
{
// Load the image.
if ( current_image != Null )
{
current_image.Dispose();
current_image = Null;
}
current_image = (Bitmap)Image.FromFile(imagesfilepath[i], true);
// Resize it.
// Save it.
}
The exception is generally thrown after 1.5 GB has been used. I can get around this issue by limiting the amount of images a user can resize at one time, but shouldn't I be able to just allocate memory for 1 Bitmap, and reuse it every iteration?