1
0
Fork 0

store garbage collector id (again) in the listener class, and free the

handler on destruction. There's no explicit Nasal command for removing
a listener, but deleting the node should fully remove them.
This commit is contained in:
mfranz 2006-02-04 16:37:25 +00:00
parent e51cd8eaf5
commit d1fa3f9c7e
2 changed files with 8 additions and 4 deletions

View file

@ -617,9 +617,8 @@ void FGNasalSys::setListener(int argc, naRef* args)
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

View file

@ -112,8 +112,12 @@ private:
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;
@ -129,6 +133,7 @@ public:
private:
friend class FGNasalSys;
naRef _handler;
int _gcKey;
FGNasalSys* _nas;
};