I am developing a windows form application. At one of my form i place a picture box control. Its working fine for majority of time. But sometime it displays red cross rather than displaying actual picture.
I further explore this and came to know that this control handle exceptions internally. So i go to Debug->Exceptions
and Check the relevant thrown
boxes. Then i found that the red box is display due to following error:
A first chance exception of type 'System.OutOfMemoryException' occurred in System.Drawing.dll
Additional information: Out of memory.
Could any body suggest me how to deal with this exception?
As pair to you comment that you are using multiple images in the PictureBox
, You should "like @Jason suggested" dispose the old image before applying the new one, like:
private void ChangePictureBoxImage(Image image)
{
pictureBox.Image.Dispose();//dispose the old image.
pictureBox.Image = image;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With