ImageList
オブジェクトを処理する適切な方法は何ですか?ImageListを廃棄する
私はprivate ImageList imageList
のメンバーを持つクラスがあるとします。私はそこにあると確信している
public void Dispose()
{
if (!disposed)
{
// Is this enough?
if (imageList != null)
imageList.Dispose();
disposed = true;
}
}
:次のように行われ、私はDispose
メソッドの実装を持っている同じクラスでは、
// Basically, lazy initialization.
if (imageList == null)
{
imageList = new ImageList();
Image[] images = Provider.CreateImages(...);
foreach (var image in images)
{
// Does the 'ImageList' perform implicit copying here
// or does it aggregate a reference?
imageList.Images.Add(image);
// Do I need to do this?
//image.Dispose();
}
}
return imageList;
:今、いくつかの瞬間に、私は次のコードを実行しますこのコードでいくつかの潜在的な問題がありますので、正しいものにしてください。
関連:[イメージリスト:元の画像を配置すると、リストから削除](http://stackoverflow.com/questions/17639237/imagelist-disposing-the-original-image-removes-it-from-リスト)。 [ImageList'の 'originals'フィールドの[参照元]のコメント(https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ImageList.cs,75)読書する価値もある。 – jrh