From: mfranz Date: Sat, 4 Feb 2006 16:37:25 +0000 (+0000) Subject: store garbage collector id (again) in the listener class, and free the X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d1fa3f9c7eb24ed1cc78dc1ec2866e5392a507a0;p=flightgear.git 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. --- diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 001ee7043..8951df67c 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -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 diff --git a/src/Scripting/NasalSys.hxx b/src/Scripting/NasalSys.hxx index d99637719..b67e108fb 100644 --- a/src/Scripting/NasalSys.hxx +++ b/src/Scripting/NasalSys.hxx @@ -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; };