|
From: | Neil Cawse |
Subject: | [DotGNU]lesson in dispose |
Date: | Sat, 15 Nov 2003 14:32:32 -0500 |
Can you tell me if Im on the right track here with regards
to disposing managed resources. Take for example toolbar which uses imagelist,
which uses ImageList.ImageCollection, which uses Image etc.. Is it a “rule” that we should implement IDisposable
if we have any local objects who in turn implement IDisposable. And then we
have to call their Dispose method when ours is called? Do we just leave finalizers? Is this correct? Toolbar: protected override void Dispose(bool disposing) { if
(disposing) { if
(imageList != null) { imageList.RecreateHandle
-= new EventHandler(ImageListHandler); #if CONFIG_COMPONENT_MODEL imageList.Dispose(); #else imageList.Dispose(disposing); #endif } } base.Dispose(disposing); } In ImageList: #if CONFIG_COMPONENT_MODEL protected override void Dispose(bool disposing) #else public void Dispose(bool disposing) #endif { images.Dispose();
// instance of ImageList.ImageCollection } In ImageList.ImageCollection: internal void Dispose() { if
(images == null) return; for
(int i = 0; i < images.Count; i++) (images[i]
as Image).Dispose(); } Thanks Neil |
[Prev in Thread] | Current Thread | [Next in Thread] |