It's all about memory usage.
I have done a small test, and here is the result. I create only a 500x500 Bitmap, but many times, without disposing it:
private void button1_Click(object sender, EventArgs e)
{
int maxIterations = 5000;
bool exceptionOccured = false;
for (int i = 0; i < maxIterations; i++)
{
Bitmap bitmap = null;
try
{
bitmap = new Bitmap(500, 500);
}
catch (Exception ex)
{
MessageBox.Show("Exception after " + i.ToString() + " iterations" + Environment.NewLine + ex.Message);
exceptionOccured = true;
break;
}
finally
{
//dispose the bitmap when you don't need it anymore (comment/uncomment to see the different result)
//bitmap?.Dispose();
}
}
if (!exceptionOccured)
{
MessageBox.Show("No exception after " + maxIterations.ToString() + " iterations");
}
}
And the result (the bitmap was not disposed):

The same code, but disposing the bitmap in the finally block:
private void button1_Click(object sender, EventArgs e)
{
int maxIterations = 5000;
bool exceptionOccured = false;
for (int i = 0; i < maxIterations; i++)
{
Bitmap bitmap = null;
try
{
bitmap = new Bitmap(500, 500);
}
catch (Exception ex)
{
MessageBox.Show("Exception after " + i.ToString() + " iterations" + Environment.NewLine + ex.Message);
exceptionOccured = true;
break;
}
finally
{
//dispose the bitmap when you don't need it anymore (comment/uncomment to see the different result)
bitmap?.Dispose();
}
}
if (!exceptionOccured)
{
MessageBox.Show("No exception after " + maxIterations.ToString() + " iterations");
}
}
And the result (the bitmap was disposed):
