On Wednesday, 7 November 2012 at 13:59:53 UTC, Kagamin wrote:
On Tuesday, 6 November 2012 at 15:31:42 UTC, eskimo wrote:
Signals are a way of a very loose coupling of components. This
loose
coupling is the reason why people usually expect weak reference
semantics from signals. So people expect a signal connection
to simply
vanish when the observer object dies, instead of keeping it
alive
because it holds a reference to it.
As long as you keep strong reference to the observer, it won't
die.
Having signals with weak reference semantics can be surprising
for a garbage collected language: AFAIK Java and C# use strong
reference semantics for observers. On the other hand one may
want strong reference semantics: if you have e.g. a
button.click listener, you don't want it to die prematurely, do
you?
Note that in C#, event subscribers are one of the most common
sources of memory leaks. It's likely the most common memory leak
period, but because in most situations you don't have tens of
thousands of subscribers people don't notice. When you do though,
things get messy.