From: Anthony Geay Date: Mon, 8 Jul 2019 12:12:01 +0000 (+0200) Subject: [EDF19803] : Free memory for reused PyScriptNode node name. PyScriptNode_ptr ref... X-Git-Tag: V9_4_0a1~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cce29cac77776f885e11442c4bcad081cd86e1ef;p=modules%2Fkernel.git [EDF19803] : Free memory for reused PyScriptNode node name. PyScriptNode_ptr ref counting is set to 1 on creation instead of 2. --- diff --git a/idl/SALOME_Component.idl b/idl/SALOME_Component.idl index ec646a904..a9bc2ef54 100644 --- a/idl/SALOME_Component.idl +++ b/idl/SALOME_Component.idl @@ -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. diff --git a/src/Container/Container_i.cxx b/src/Container/Container_i.cxx index 8b2c05eab..7d06ff0ec 100644 --- a/src/Container/Container_i.cxx +++ b/src/Container/Container_i.cxx @@ -258,18 +258,7 @@ Engines_Container_i::~Engines_Container_i() delete _id; if(_NS) delete _NS; - for(std::map::iterator it=_dftPyNode.begin();it!=_dftPyNode.end();it++) - { - Engines::PyNode_var tmpVar((*it).second); - if(!CORBA::is_nil(tmpVar)) - tmpVar->UnRegister(); - } - for(std::map::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::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::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. * diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index 56ba2be21..5a68451df 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -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