ImageList
개체를 처리하는 적절한 방법은 무엇입니까?ImageList 처분
일부 클래스에 private ImageList imageList
회원이 있다고 가정 해 보겠습니다. 자, 어떤 순간에 나는 다음과 같은 코드를 수행 : 같은 클래스에서
// 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;
을 내가 가지고있는 다음과 같은 방법으로 수행되는 Dispose
방법의 구현 :
public void Dispose()
{
if (!disposed)
{
// Is this enough?
if (imageList != null)
imageList.Dispose();
disposed = true;
}
}
내가 거기에 확신을 이 코드의 일부 잠재적 인 문제가 있으므로 올바른 수정을 도와주십시오.
관련 ([의 ImageList 원 화상을 배치하는 것은 목록으로부터 삭제] http://stackoverflow.com/questions/17639237/imagelist-disposing-the-original-image-removes-it-from- the-list). [ImageList의 원본 항목] 필드에있는 [참조 소스]의 주석 (https://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/ImageList.cs,75) 읽을 가치가 있습니다. – jrh