Define "safely" ;-p
:-)))
In principle I assumed that whenever we explicitly make the object unusable
(closed/disposed... whatever), we will also explicitly remove the delegates
from the map in question.
I was not sure about what would happen in implicit cases, specifically
including the case when the object in question goes out of scope. I could
also think of such situations like power management issues, etc. i.e.
situations not caused directly via our code.
This type of delegate (to an otherwise unreferenced object) is fine by
itself, but be aware that if used inappropriately this type of hanging
reference (especially events) is a common cause of memory issues -
i.e. event subscriptions keeping thousands of objects from being
collected. For example:
http://www.codeproject.com/KB/showca...SProfiler.aspx
In fact we also want to implement an event subscription mechanism ;-), so we
take the same risk. Of course we assume that all event subscriptions will be
deleted each time we explicitly make the subscribed object unusable. It
would be nice to automatise it somehow, so that the programmer does not have
to think too much about it every time the object gets explicitly disposed.
The problem is that I do not know how to use inheritance for this, because
the objects' classes are going to inherit various other business logic
classes...
If you possibly know about a description of some nice event subscription
mechanism, please let me know ;-)
Yours
DoB.