N
Nicholas Sherlock
Hey all,
I'm trying to write a class which will need to maintain a list of
listeners, so that it can notify them when events occur. But if objects
register themselves as listeners, then forget to un-register, they can't
be released from memory by the garbage collector. Should I implement my
list of listeners as a WeakHashMap with listeners as keys and null
values? It seems like a WeakSet would be more appropriate.
How do you solve this problem?
Cheers,
Nicholas Sherlock
I'm trying to write a class which will need to maintain a list of
listeners, so that it can notify them when events occur. But if objects
register themselves as listeners, then forget to un-register, they can't
be released from memory by the garbage collector. Should I implement my
list of listeners as a WeakHashMap with listeners as keys and null
values? It seems like a WeakSet would be more appropriate.
How do you solve this problem?
Cheers,
Nicholas Sherlock