> Further looking at the code I came to the conclusion (untested) that if
> there are no references to the subject anywhere (say it was created and
> used locally in a method to register one or more listeners that have
> application scope), subject and all its listeners will be removed from
> the event manager, even though the listeners themselves are not
> deallocated yet. I don't know if I am wrong here, I guess we need to
> test this assumption.
I rethought the situation and this sounds about right to me, and is also
what I would expect..do you think this is wrong? I made this intentionally
so that people don't have to unregister their listeners; if we would rely
on explicit unregistering, I can guarantee that people will 'forget' and
create 'leaks'. Making the registration depend on the subject's lifecycle
solves this, unless I'm forgetting something.
> make it explicit in the docs that users must hold on to their subjects
Yes!
> (which may scare lost of Java ppl. who never had to deal with reference
> counting, and manually freeing memory :-)).
If the subject goes away, it means it is not used by anybody anymore as a
communications channel and its registered listeners are 'free' again,
although they can still live on by themselves. By simply keeping the
subject around (e.g. by making it a static global somewhere for subjects
that should never go away) all this will never happen and the entire
problem goes away - standard Java reference semantics.
Holger
This archive was generated by hypermail 2.0.0 : Tue Nov 25 2003 - 07:13:45 EST