I have an object, which has an event which in turn has subscribers.
I know that the subscribing objects won't get GC'ed since the delegate they stored for the event is connected to them, thus keeping them connected with the object graph, until one explicitly unsubscribes them. This is only logical since otherwise nothing good will happen when the event is fired.
Does this apply to the Event-owner as well?
I would think it does not, since the subscribing objects do not have a connection to it, to my knowledge.
And again using common sense (which I know does not neccessarily relate to IT-reality):
Nothing bad can happen if the event-owner is GC'ed, only the event will never fire (again).
Is this assumption correct?
Best Answer
Yes, I believe your assumption is correct. I also tried to write some (ugly) code to test this hypothesis:
Output: Keeps writing:
If you keep the other object alive, neither object is collected, as we knew.
Both objects are collected if we leave out the
keepAlive
lines entirely.