20,741
edits
No edit summary |
|||
Line 1: | Line 1: | ||
== Motivation == | |||
{{FGCquote | |||
|1= Someone recently pointed out that the setlistener() / removelistener() API makes it easy to leak resources. So I wondered about making an alternate API where the return value from setlistener '''must''' be kept, or the listener is removed. I can imagine this with a helper object | |||
<syntaxhighlight lang="nasal"> | |||
var myL = setlistener2("some/prop", func { ... }} ) | |||
myL.addprop("some/other/prop"); | |||
myL.addprop("yet/another/prop"); | |||
</syntaxhighlight> | |||
Now you need to retain a ref to myL or the listeners on all the props are removed. I don't think we can retro-fit this to the existing API, because I suspect many places just ignore the return value and would break with this change. | |||
(Or even pass a vec of property names to setlistener2, to avoid all the discrete calls to 'addprop', that's a seperate detail really) | |||
It seems like this would work, and be easy enough to implement - question is if it gives enough benefit to be worth the confusion. | |||
|2= {{cite web | |||
| url = http://forum.flightgear.org/viewtopic.php?p=192767#p192767 | |||
| title = <nowiki>Listener objects</nowiki> | |||
| author = <nowiki>zakalawe</nowiki> | |||
| date = Oct 28th, 2013 | |||
}} | |||
}} | |||
== Background == | == Background == | ||
{{FGCquote | {{FGCquote | ||
Line 48: | Line 69: | ||
}} | }} | ||
{{FGCquote | {{FGCquote |