[GUI] Re: Events and finalizers
Mon, 10 Mar 2003 18:12:19 +0100
Nick wrote (snipped)
> The true problem here is that once you got an Event, you never uninstall
> the callback, even if you just take the first n events and then stop
> using the stream. This can be really expensive; do you use finalizers to
> uninstall the callback?
Well there are two approaches:
(1) you provide a more complicated function which in addition to the new
event, returns an IO () action which unbinds it. This is what HTk
does, in general, though for many simple examples it is of course not
(2) in many but not all cases it is possible to work out that the stream
can be automatically deregistered. For example, as well as finalizers
you can also forget the stream when the object is destroyed.
Of course this isn't anything particular to do with events; a callback
model also has to have a way of deinstalling the callback.