Salome HOME
[EDF19803] : Free memory for reused PyScriptNode node name. PyScriptNode_ptr ref...
authorAnthony Geay <anthony.geay@edf.fr>
Mon, 8 Jul 2019 12:12:01 +0000 (14:12 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Mon, 8 Jul 2019 12:12:01 +0000 (14:12 +0200)
idl/SALOME_Component.idl
src/Container/Container_i.cxx
src/Container/SALOME_Container_i.hxx

index ec646a904e3a961b915959685eaa6dc9b1385150..a9bc2ef548630b8a1abe8641cadaa203c25acf66 100644 (file)
@@ -235,6 +235,12 @@ module Engines
 
     //! Retrieves the last created PyScriptNode instance with createPyScriptNode.
     PyScriptNode getDefaultPyScriptNode(in string nodeName);
+
+    //! This method remove all refs of PyScriptNode servant objects stored in server.
+    /*!
+     * Previous scripts created on container may have been stored in a map. This method removes them. It then clean all the contexts dict attached to them.
+     */
+    void cleanAllPyScripts();
   };
 
   /*! \brief Interface of the %component.
index 8b2c05eab1675dffd123815fe5d97949ed3e8908..7d06ff0ec32ef4a9cf2f262dce90e88c9b5a3d1b 100644 (file)
@@ -258,18 +258,7 @@ Engines_Container_i::~Engines_Container_i()
     delete _id;
   if(_NS)
     delete _NS;
-  for(std::map<std::string,Engines::PyNode_var>::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++)
-  {
-    Engines::PyNode_var tmpVar((*it).second);
-    if(!CORBA::is_nil(tmpVar))
-      tmpVar->UnRegister();
-  }
-  for(std::map<std::string,Engines::PyScriptNode_var>::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++)
-  {
-    Engines::PyScriptNode_var tmpVar((*it).second);
-    if(!CORBA::is_nil(tmpVar))
-      tmpVar->UnRegister();
-  }
+  cleanAllPyScripts();
 }
 
 //=============================================================================
@@ -1749,8 +1738,6 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
         oldNode->UnRegister();
       (*it).second=node;
     }
-    if(!CORBA::is_nil(node))
-      node->Register();
     return node._retn();
   }
   else
@@ -1762,6 +1749,24 @@ Engines::PyScriptNode_ptr Engines_Container_i::createPyScriptNode(const char* no
   }
 }
 
+void Engines_Container_i::cleanAllPyScripts()
+{
+  for(std::map<std::string,Engines::PyNode_var>::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++)
+    {
+      Engines::PyNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        tmpVar->UnRegister();
+    }
+  _dftPyNode.clear();
+  for(std::map<std::string,Engines::PyScriptNode_var>::iterator it=_dftPyScriptNode.begin();it!=_dftPyScriptNode.end();it++)
+    {
+      Engines::PyScriptNode_var tmpVar((*it).second);
+      if(!CORBA::is_nil(tmpVar))
+        tmpVar->UnRegister();
+    }
+  _dftPyScriptNode.clear();
+}
+
 //=============================================================================
 /*! \brief Retrieves the last created PyScriptNode instance with createPyScriptNode.
  *
index 56ba2be21c9d078d33b768d6887e136cce6bb349..5a68451dffd9573283e66dbaf2a91b318eca4a8b 100644 (file)
@@ -111,6 +111,7 @@ public:
   Engines::PyNode_ptr createPyNode(const char* nodeName, const char* code);
   Engines::PyNode_ptr getDefaultPyNode(const char *nodeName);
   Engines::PyScriptNode_ptr createPyScriptNode(const char* nodeName, const char* code);
+  void cleanAllPyScripts();
   Engines::PyScriptNode_ptr getDefaultPyScriptNode(const char *nodeName);
   // --- local C++ methods