Salome HOME
Optimize usage of context for PythonNode (by deleting input and output port PyObject...
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 21 Jun 2023 07:05:03 +0000 (09:05 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 22 Aug 2023 10:54:53 +0000 (12:54 +0200)
src/runtime/PythonNode.cxx
src/yacsloader/Test/YacsLoaderTest.cxx

index d0f40b944e9c461cf7475940d33185cf9af92f90..cbc2ff4df921c03d639766b994ace6c465c11a97 100644 (file)
@@ -780,6 +780,8 @@ void PythonNode::executeLocal()
             cerr << endl;
 #endif
             p->put(ob);
+            if(!isUsingPythonCache())
+              PyDict_DelItemString(_context,p->getName().c_str());
           }
     }
     catch(ConversionException& ex)
@@ -790,6 +792,15 @@ void PythonNode::executeLocal()
     if(_autoSqueeze)
       squeezeMemory();
     DEBTRACE( "-----------------End PyNode::outputs-----------------" );
+    if(!isUsingPythonCache())
+    {
+      for(iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++)
+      {
+        AutoPyRef pStr = PyUnicode_FromString( (*iter2)->getName().c_str() );
+        if( PyDict_Contains(_context,pStr) == 1 )
+          { PyDict_DelItem(_context,pStr); }
+      }
+    }
   }
   DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" );
 }
index 43df387c81fa344ba7f472aab6b5cc6ac1b67fed..109145e8acee9f2458332a787080141c15836844 100644 (file)
@@ -654,7 +654,7 @@ void YacsLoaderTest::refcnt()
   ret = driverTest(p, "samples/refcnt2.xml");
   CPPUNIT_ASSERT(ret == 0);
   data = ((OutputPyPort*)p->nodeMap["b1.b.node1"]->getOutputPort("p1"))->get();
-  CPPUNIT_ASSERT(data->ob_refcnt==19);
+  CPPUNIT_ASSERT_EQUAL(data->ob_refcnt,(long int)13);
 }
 
 void YacsLoaderTest::foreachs()