handler on destruction. There's no explicit Nasal command for removing
a listener, but deleting the node should fully remove them.
if(!(naIsCode(handler) || naIsCCode(handler) || naIsFunc(handler)))
return;
- gcSave(handler);
bool initial = argc > 2 && naTrue(args[2]);
- node->addChangeListener(new FGNasalListener(handler, this), initial);
+ node->addChangeListener(new FGNasalListener(handler, this, gcSave(handler)), initial);
}
// functions providing access to the NasalDisplay - used to display text directly on the screen
class FGNasalListener : public SGPropertyChangeListener {
public:
- FGNasalListener(naRef handler, FGNasalSys* nasal)
- : _handler(handler), _nas(nasal) {}
+ FGNasalListener(naRef handler, FGNasalSys* nasal, int key)
+ : _handler(handler), _gcKey(key), _nas(nasal) {}
+
+ ~FGNasalListener() {
+ _nas->gcRelease(_gcKey);
+ }
void valueChanged(SGPropertyNode* node) {
_nas->_cmdArg = node;
private:
friend class FGNasalSys;
naRef _handler;
+ int _gcKey;
FGNasalSys* _nas;
};