so i got this program that i built. there's some of the code
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
if (openDialog.ShowDialog() == DialogResult.OK)
{
image1 = new Bitmap(openDialog.FileName);
pictureBox1.Image = image1;
}
}
now every time that i change the picture with the button the ram usage is increased. a friend of mine told me that's happened because i'm assign new memory space every time i'm doing this :
new Bitmap(openDialog.Filename);
what's the solution for this? (i tried to search in google but i didnt really know what to search for that..)
EDIT :
now its working thanks for help. edited code for others :
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openDialog = new OpenFileDialog();
if (openDialog.ShowDialog() == DialogResult.OK)
{
if (pictureBox1.Image != null)
pictureBox1.Image.Dispose();
image1 = new Bitmap(openDialog.FileName);
pictureBox1.Image = image1;
}
}