Re: EventSubject as WeakHashMap key in EventManager

From: Holger Hoffstätte (holge..izards.de)
Date: Mon Nov 24 2003 - 07:52:34 EST

  • Next message: Holger Hoffstätte: "Thoughts on EventManager & async posting"

    On Fri, 21 Nov 2003, Andrus Adamchik wrote:

    > I remember there was a discussion way back about weak references in the
    > event mechanism. Now that I am doing lots of testing with it (and btw,
    > 1.1 EventManager seems to be very robust), I ran a few times into a
    > problem of deallocated invocation queues due to the fact that
    > EventSubject used wasn't owned by any object, but instead was created
    > locally.

    Can you point me to an example? Is it one of the unit tests?
    In general even WeakReferences are generally at least valid for the
    current method context and all its children when used as argument; I don't
    think the language would work otherwise. It's also unlikely that you'd
    create a free-flying subject over and over again, since you wouldn't have
    the opportunity to actually register anything with it..

    Certainly one interesting thing about regular WeakReferences is their
    somewhat aggressive behaviour, i.e. they are zapped ASAP. On the other
    hand this will expose dangling reference bugs immediately.

    > What was the original reason for making EventSubject a weak key as
    > opposed to say manually cleaning the invocation queues whose items have
    > been deallocated?

    Just looked over it again and I don't think I remember any explicit reason
    for that. If I remember correctly at first the subjects were not even
    weak, but when I wrote the (admittedly flaky) subject GC test I realized
    that they had to be weak when used as keys (as it is in our case).
    I guess manually pruning could have worked as well, although I find the
    weak approach cleaner. Introducing manual cleaning just makes things more
    complicated, IMHO.

    Holger



    This archive was generated by hypermail 2.0.0 : Mon Nov 24 2003 - 07:52:44 EST