>どうしても共有しているかどうか不明なものについては仕方ないとしても、自分で管理可能なものについては極力管理する努力をするべきです。
まぁ、そうなんですけど、入れ替えのときは必ず Dispose という流れになっているのはどうかなと思いまして。
例えば、以下の2つのパターンによって変わりませんか?
-----------------(1)
class Form1 : Form
{
void f1()
{
pictureBox.Image = Image.FromFile(filePath);
}
voidf2()
{
pictureBox.Image.Dispose();
pictureBox.Image = Image.FromFile(filePath);
}
}
-----------------(2)
class Form1 : Form
{
Image image;
void f0()
{
image = Image.FromFile(filePath);
}
void f1()
{
pictureBox.Image = image;
}
voidf2()
{
// ?
// pictureBox.Image.Dispose();
pictureBox.Image = Image.FromFile(filePath);
}
}
>可能性はあるけど、それ前提でやってたら Dispose() も using もまるで出来なくなっちゃいますぜ。
という事なので、管理できるかどうかの前提を持つべきだとは思います。
|