T
Tony Johansson
When I want to dispose the Image(theImage) which of these two methods namned
1 and 2 below is best practice to use ?
Both will dispose the Image but they use somewhat different ways.
public partial class Form1 : Form
{
private Image theImage;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.Opaque, true);
theImage = new Bitmap("logo.gif");
1 theImage.Dispose();
}
}
protected override void Dispose(bool disposing)
{
2 if (disposing)
2 {
2 theImage.Dispose();
2 }
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
//Tony
1 and 2 below is best practice to use ?
Both will dispose the Image but they use somewhat different ways.
public partial class Form1 : Form
{
private Image theImage;
public Form1()
{
InitializeComponent();
SetStyle(ControlStyles.Opaque, true);
theImage = new Bitmap("logo.gif");
1 theImage.Dispose();
}
}
protected override void Dispose(bool disposing)
{
2 if (disposing)
2 {
2 theImage.Dispose();
2 }
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
//Tony