This normally shouldn't be neccessary in C# because .NET's garbage collection will take care of it for you - but if you want to get that warm and fuzzy from disposing an object yourself:
When you are getting ready to assign the image to your picturebox - first grab the existing picture (if any) and dispose of it after making the assignment.
[code] var newImage = new Bitmap(100, 100); var oldImage = pictureBox1.Image; pictureBox1.Image = newImage; oldImage.Dispose(); [/code]
it is important to not dispose of an image while it is still attached to the picture box because if the picture box control tries to redraw or use the image for anything it will crash. ><//~Psightoplasm`~
Comments
When you are getting ready to assign the image to your picturebox - first grab the existing picture (if any) and dispose of it after making the assignment.
[code]
var newImage = new Bitmap(100, 100);
var oldImage = pictureBox1.Image;
pictureBox1.Image = newImage;
oldImage.Dispose();
[/code]
it is important to not dispose of an image while it is still attached to the picture box because if the picture box control tries to redraw or use the image for anything it will crash.
><//~Psightoplasm`~