From e673545f08c1d57f91f5c42d8092aba68dde75eb Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 24 Jan 2008 12:29:08 +0000 Subject: [PATCH] NPAL18604: Pb. of performance with MakeVertex. Fixed memory leak and improved OCAF data management for particular case. --- src/GEOM/GEOM_Engine.cxx | 52 ++++++++++++++++++++++++++------ src/GEOM/GEOM_Engine.hxx | 2 ++ src/GEOM_I/GEOM_IOperations_i.cc | 4 +-- 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index 3ac30e5ab..bf231425c 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -114,6 +114,7 @@ GEOM_Engine::GEOM_Engine() _OCAFApp = new GEOM_Application(); _UndoLimit = 10; + _lastObjectTag = 0; } //============================================================================= @@ -176,18 +177,34 @@ Handle(GEOM_Object) GEOM_Engine::GetObject(int theDocID, char* theEntry) //============================================================================= Handle(GEOM_Object) GEOM_Engine::AddObject(int theDocID, int theType) { - Handle(TDocStd_Document) aDoc = GetDocument(theDocID); - Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main()); + Handle(TDocStd_Document) aDoc = GetDocument(theDocID); + Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main()); - TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main()); - Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType); + //TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main()); + // NPAL18604: use existing label to decrease memory usage, + // if this label has been freed (object deleted) + bool useExisting = false; + TDF_Label aChild; + if (_lastObjectTag > 0) { + aChild = aDoc->Main().FindChild(_lastObjectTag, Standard_False); + if (!aChild.IsAttribute(TDataStd_TreeNode::GetDefaultTreeID())) { + useExisting = true; + } + } + if (!useExisting) { + // create new label + aChild = TDF_TagSource::NewChild(aDoc->Main()); + _lastObjectTag = aChild.Tag(); + } + + Handle(GEOM_Object) anObject = new GEOM_Object(aChild, theType); - //Put an object in the map of created objects - TCollection_AsciiString anID = BuildIDFromObject(anObject); - if(_objects.IsBound(anID)) _objects.UnBind(anID); - _objects.Bind(anID, anObject); + //Put an object in the map of created objects + TCollection_AsciiString anID = BuildIDFromObject(anObject); + if(_objects.IsBound(anID)) _objects.UnBind(anID); + _objects.Bind(anID, anObject); - return anObject; + return anObject; } //============================================================================= @@ -204,7 +221,22 @@ Handle(GEOM_Object) GEOM_Engine::AddSubShape(Handle(GEOM_Object) theMainShape, Handle(TDocStd_Document) aDoc = GetDocument(theMainShape->GetDocID()); Handle(TDataStd_TreeNode) aRoot = TDataStd_TreeNode::Set(aDoc->Main()); - TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main()); + //TDF_Label aChild = TDF_TagSource::NewChild(aDoc->Main()); + // NPAL18604: use existing label to decrease memory usage, + // if this label has been freed (object deleted) + bool useExisting = false; + TDF_Label aChild; + if (_lastObjectTag > 0) { + aChild = aDoc->Main().FindChild(_lastObjectTag, Standard_False); + if (!aChild.IsAttribute(TDataStd_TreeNode::GetDefaultTreeID())) { + useExisting = true; + } + } + if (!useExisting) { + // create new label + aChild = TDF_TagSource::NewChild(aDoc->Main()); + _lastObjectTag = aChild.Tag(); + } Handle(GEOM_Function) aMainShape = theMainShape->GetLastFunction(); Handle(GEOM_Object) anObject = new GEOM_Object(aChild, 28); //28 is SUBSHAPE type diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index 662bd242f..d3fe9a3f7 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -101,6 +101,8 @@ class GEOM_Engine GEOM_DataMapOfAsciiStringTransient _objects; Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap; + + int _lastObjectTag; }; #endif diff --git a/src/GEOM_I/GEOM_IOperations_i.cc b/src/GEOM_I/GEOM_IOperations_i.cc index 89b7fc5f8..3d5c87c46 100644 --- a/src/GEOM_I/GEOM_IOperations_i.cc +++ b/src/GEOM_I/GEOM_IOperations_i.cc @@ -114,7 +114,7 @@ void GEOM_IOperations_i::FinishOperation() //============================================================================= /*! - * AboutOperation + * AbortOperation */ //============================================================================= void GEOM_IOperations_i::AbortOperation() @@ -132,6 +132,6 @@ GEOM::GEOM_Object_ptr GEOM_IOperations_i::GetObject(Handle(GEOM_Object) theObjec if(theObject.IsNull()) return NULL; TCollection_AsciiString anEntry; TDF_Tool::Entry(theObject->GetEntry(), anEntry); - GEOM::GEOM_Object_var GO = GEOM::GEOM_Object::_duplicate(_engine->GetObject(theObject->GetDocID(), anEntry.ToCString())); + GEOM::GEOM_Object_var GO = _engine->GetObject(theObject->GetDocID(), anEntry.ToCString()); return GO._retn(); } -- 2.39.2