]> git.mxchange.org Git - flightgear.git/commitdiff
store garbage collector id (again) in the listener class, and free the
authormfranz <mfranz>
Sat, 4 Feb 2006 16:37:25 +0000 (16:37 +0000)
committermfranz <mfranz>
Sat, 4 Feb 2006 16:37:25 +0000 (16:37 +0000)
handler on destruction. There's no explicit Nasal command for removing
a listener, but deleting the node should fully remove them.

src/Scripting/NasalSys.cxx
src/Scripting/NasalSys.hxx

index 001ee7043a384fda8657962bc866b7b4904ed4e4..8951df67c4f239fc37ee12ae7b161b2a456530b0 100644 (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
index d99637719a8863ce3d735890dcdf660f39ec8fa7..b67e108fb8822cc42376705c8be885b4e4a69b8d 100644 (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;
 };