From: jfa Date: Fri, 1 Feb 2008 11:45:08 +0000 (+0000) Subject: patchGeomMemoryLeaks.dat by Christian CAREMOLI. X-Git-Tag: for_M2008_07022008~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=67d3018cd8d0210b1b54a897e2a5c4efa89d142d;p=modules%2Fgeom.git patchGeomMemoryLeaks.dat by Christian CAREMOLI. --- diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index a02a558f3..5bc00d051 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -117,6 +117,25 @@ GEOM_Engine::GEOM_Engine() //_lastObjectTag = 0; } +/*! + * Destructor + */ +GEOM_Engine::~GEOM_Engine() +{ + GEOM_DataMapIteratorOfDataMapOfAsciiStringTransient It(_objects); + for(; It.More(); It.Next()) + { + RemoveObject(Handle(GEOM_Object)::DownCast(It.Value())); + } + + //Close all documents not closed + for(Interface_DataMapIteratorOfDataMapOfIntegerTransient anItr(_mapIDDocument); anItr.More(); anItr.Next()) + Close(anItr.Key()); + + _mapIDDocument.Clear(); + _objects.Clear(); +} + //============================================================================= /*! * GetDocument diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index 52d418dd0..ab6b82821 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -36,7 +36,7 @@ class GEOM_Engine { public: Standard_EXPORT GEOM_Engine(); - Standard_EXPORT ~GEOM_Engine() { _mapIDDocument.Clear(); _objects.Clear(); } + Standard_EXPORT virtual ~GEOM_Engine(); //Retuns the engine Standard_EXPORT static GEOM_Engine* GetEngine(); diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc index 0ba246973..106ee9ef6 100644 --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -565,8 +565,8 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::AddInStudy(SALOMEDS::Study_ptr theStudy, GEOM: //============================================================================ void GEOM_Gen_i::register_name(char * name) { - GEOM::GEOM_Gen_ptr g = GEOM::GEOM_Gen::_narrow(_this()); - name_service->Register(g, CORBA::string_dup(name)); + GEOM::GEOM_Gen_var g = _this(); + name_service->Register(g, name); } //============================================================================ @@ -599,6 +599,7 @@ GEOM::GEOM_IBasicOperations_ptr GEOM_Gen_i::GetIBasicOperations(CORBA::Long theS GEOM::GEOM_Gen_ptr engine = _this(); + //transfer reference on engine GEOM_IBasicOperations_i* aServant = new GEOM_IBasicOperations_i(_poa, engine, _impl->GetIBasicOperations(theStudyID)); @@ -928,7 +929,8 @@ GEOM_I_EXPORT const char * interfaceName) { GEOM_Gen_i * myGEOM_Gen_i = new GEOM_Gen_i(orb, poa, contId, instanceName, interfaceName); - myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example + // Don't understand the reason of this register ???? +// myGEOM_Gen_i->register_name("/myGEOM_Gen"); // NRI : 11/07/2002 : Add for Supervision example return myGEOM_Gen_i->getId(); } } diff --git a/src/GEOM_I/GEOM_I3DPrimOperations_i.cc b/src/GEOM_I/GEOM_I3DPrimOperations_i.cc index 276a9d556..207c99708 100644 --- a/src/GEOM_I/GEOM_I3DPrimOperations_i.cc +++ b/src/GEOM_I/GEOM_I3DPrimOperations_i.cc @@ -247,8 +247,9 @@ GEOM::GEOM_Object_ptr GEOM_I3DPrimOperations_i::MakeSpherePntR if (thePnt == NULL) return aGEOMObject._retn(); //Get the reference point + CORBA::String_var entry=thePnt->GetEntry(); Handle(GEOM_Object) aPnt = GetOperations()->GetEngine()->GetObject - (thePnt->GetStudyID(), thePnt->GetEntry()); + (thePnt->GetStudyID(), entry); if (aPnt.IsNull()) return aGEOMObject._retn(); diff --git a/src/GEOM_I/GEOM_IBooleanOperations_i.cc b/src/GEOM_I/GEOM_IBooleanOperations_i.cc index 836451282..57dabf6a6 100644 --- a/src/GEOM_I/GEOM_IBooleanOperations_i.cc +++ b/src/GEOM_I/GEOM_IBooleanOperations_i.cc @@ -72,10 +72,12 @@ GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn(); //Get the reference shapes + CORBA::String_var entry=theShape1->GetEntry(); Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject - (theShape1->GetStudyID(), theShape1->GetEntry()); + (theShape1->GetStudyID(), entry); + entry=theShape2->GetEntry(); Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject - (theShape2->GetStudyID(), theShape2->GetEntry()); + (theShape2->GetStudyID(), entry); if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn(); diff --git a/src/GEOM_I/GEOM_IOperations_i.hh b/src/GEOM_I/GEOM_IOperations_i.hh index 9ad5fca9a..c425449dc 100644 --- a/src/GEOM_I/GEOM_IOperations_i.hh +++ b/src/GEOM_I/GEOM_IOperations_i.hh @@ -59,7 +59,7 @@ class GEOM_I_EXPORT GEOM_IOperations_i : public virtual POA_GEOM::GEOM_IOperatio private: ::GEOM_IOperations* _impl; - GEOM::GEOM_Gen_ptr _engine; + GEOM::GEOM_Gen_var _engine; }; #endif diff --git a/src/GEOM_I/GEOM_Object_i.cc b/src/GEOM_I/GEOM_Object_i.cc index d8794d7b9..4a86443b6 100644 --- a/src/GEOM_I/GEOM_Object_i.cc +++ b/src/GEOM_I/GEOM_Object_i.cc @@ -61,7 +61,9 @@ GEOM_Object_i::GEOM_Object_i (PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr //============================================================================= GEOM_Object_i::~GEOM_Object_i() -{} +{ + GEOM_Engine::GetEngine()->RemoveObject(_impl); +} //============================================================================= diff --git a/src/GEOM_I/GEOM_Object_i.hh b/src/GEOM_I/GEOM_Object_i.hh index 43711eacd..56631b7f0 100644 --- a/src/GEOM_I/GEOM_Object_i.hh +++ b/src/GEOM_I/GEOM_Object_i.hh @@ -85,7 +85,7 @@ class GEOM_I_EXPORT GEOM_Object_i : public virtual POA_GEOM::GEOM_Object, public private: - GEOM::GEOM_Gen_ptr _engine; + GEOM::GEOM_Gen_var _engine; Handle(GEOM_Object) _impl; TopoDS_Shape _geom; }; diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.cc b/src/GEOM_I_Superv/GEOM_Superv_i.cc index 666ec0861..ba79c1791 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.cc +++ b/src/GEOM_I_Superv/GEOM_Superv_i.cc @@ -70,6 +70,12 @@ GEOM_Superv_i::GEOM_Superv_i(CORBA::ORB_ptr orb, GEOM_Superv_i::~GEOM_Superv_i() { MESSAGE("GEOM_Superv_i::~GEOM_Superv_i"); + if (!CORBA::is_nil(myBasicOp)) + myBasicOp->Destroy(); + if (!CORBA::is_nil(myBoolOp)) + myBoolOp->Destroy(); + if (!CORBA::is_nil(my3DPrimOp)) + my3DPrimOp->Destroy(); delete name_service; } @@ -79,8 +85,8 @@ GEOM_Superv_i::~GEOM_Superv_i() //============================================================================ void GEOM_Superv_i::register_name(char * name) { - GEOM::GEOM_Superv_ptr g = GEOM::GEOM_Superv::_narrow(POA_GEOM::GEOM_Superv::_this()); - name_service->Register(g, strdup(name)); + GEOM::GEOM_Superv_var g = _this(); + name_service->Register(g, name); } //============================================================================= @@ -88,9 +94,17 @@ void GEOM_Superv_i::register_name(char * name) //============================================================================= void GEOM_Superv_i::setGeomEngine() { + if ( !CORBA::is_nil(myGeomEngine) ) + return; // get GEOM_Gen engine + /* SALOME_LifeCycleCORBA* lcc = new SALOME_LifeCycleCORBA( name_service ); Engines::Component_var comp = lcc->FindOrLoad_Component( "FactoryServer", "GEOM" ); + */ + + Engines::Container_var cont=GetContainerRef(); + cont->load_component_Library("GEOM"); + Engines::Component_var comp=cont->create_component_instance("GEOM",0); myGeomEngine = GEOM::GEOM_Gen::_narrow(comp); } @@ -799,7 +813,9 @@ GEOM::GEOM_Object_ptr GEOM_Superv_i::MakeSphere (CORBA::Double theX, MESSAGE("GEOM_Superv_i::MakeSphepe"); getBasicOp(); get3DPrimOp(); - GEOM::GEOM_Object_ptr anObj = my3DPrimOp->MakeSpherePntR(myBasicOp->MakePointXYZ(theX, theY, theZ), theRadius); + GEOM::GEOM_Object_var o = myBasicOp->MakePointXYZ(theX, theY, theZ); + GEOM::GEOM_Object_ptr anObj = my3DPrimOp->MakeSpherePntR(o, theRadius); + o->Destroy(); endService( " GEOM_Superv_i::MakeSphepe" ); return anObj; } @@ -2737,7 +2753,8 @@ extern "C" const char * interfaceName) { GEOM_Superv_i * myGEOM_Superv_i = new GEOM_Superv_i(orb, poa, contId, instanceName, interfaceName); - myGEOM_Superv_i->register_name("/myGEOM_Superv"); + //Don't understand the reason why this component is registered ??? +// myGEOM_Superv_i->register_name("/myGEOM_Superv"); return myGEOM_Superv_i->getId() ; } } diff --git a/src/GEOM_I_Superv/GEOM_Superv_i.hh b/src/GEOM_I_Superv/GEOM_Superv_i.hh index 0d3039704..18993469f 100644 --- a/src/GEOM_I_Superv/GEOM_Superv_i.hh +++ b/src/GEOM_I_Superv/GEOM_Superv_i.hh @@ -566,21 +566,21 @@ public: private: SALOME_NamingService * name_service; - GEOM::GEOM_Gen_ptr myGeomEngine; + GEOM::GEOM_Gen_var myGeomEngine; CORBA::Long myStudyID; CORBA::Long myLastStudyID; // mkr : PAL10770 PortableServer::POA_var myPOA; - GEOM::GEOM_IBasicOperations_ptr myBasicOp; - GEOM::GEOM_I3DPrimOperations_ptr my3DPrimOp; - GEOM::GEOM_IBooleanOperations_ptr myBoolOp; - GEOM::GEOM_IInsertOperations_ptr myInsOp; - GEOM::GEOM_ITransformOperations_ptr myTransfOp; - GEOM::GEOM_IShapesOperations_ptr myShapesOp; - GEOM::GEOM_IBlocksOperations_ptr myBlocksOp; - GEOM::GEOM_ICurvesOperations_ptr myCurvesOp; - GEOM::GEOM_ILocalOperations_ptr myLocalOp; - GEOM::GEOM_IGroupOperations_ptr myGroupOp; + GEOM::GEOM_IBasicOperations_var myBasicOp; + GEOM::GEOM_I3DPrimOperations_var my3DPrimOp; + GEOM::GEOM_IBooleanOperations_var myBoolOp; + GEOM::GEOM_IInsertOperations_var myInsOp; + GEOM::GEOM_ITransformOperations_var myTransfOp; + GEOM::GEOM_IShapesOperations_var myShapesOp; + GEOM::GEOM_IBlocksOperations_var myBlocksOp; + GEOM::GEOM_ICurvesOperations_var myCurvesOp; + GEOM::GEOM_ILocalOperations_var myLocalOp; + GEOM::GEOM_IGroupOperations_var myGroupOp; };