Matias Woloski <[EMAIL PROTECTED]> wrote: > I have a *ComponentCatalog* class that manages a list of > *System.ComponentModel.Component*. It's actually a façade for a > Dictionary<string,Component>. > > I want this class to be able to return each component when they are > requested, but I don't want the class to keep references to Components > when no one else is using them.
To what purpose do you keep a mapping of strings to components? I think knowing the answer to this question would help people solve your problem. > I am subscribing to the Disposed event of each component and removing > the reference from the Dictionary<string,Component> when the Component > gets disposed. However I cannot assure that the developer will call > Component.Dispose(), hence the Disposed event would never be raised > and the Component won't never be taken out from the Dictionary. > > I wonder if I should use WeakReferences to do this, and what would be > the drawback of doing so. I'm not 100% sure what you want to know or what you're trying to achieve. Are you unclear on the semantics of WeakReferences? WeakReferences permit collection of the inner reference, so certainly, it will stop the dictionary keeping the component alive forever. However, you'll still have to do periodic scans to clear out any dead references, to actually remove items from the dictionary. -- Barry -- http://barrkel.blogspot.com/ =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com