From 0f524ba023316f3d0a4d34fb89a3979742262b89 Mon Sep 17 00:00:00 2001 From: skv Date: Mon, 12 Mar 2012 19:28:31 +0400 Subject: [PATCH] 0023005: Unjustified memory grow during undo/redo operation --- src/NIS/NIS_Drawer.cxx | 2 ++ src/NIS/NIS_InteractiveContext.cxx | 47 +++++++++++++++++++++--------- src/NIS/NIS_InteractiveContext.hxx | 14 +++++---- src/NIS/NIS_ObjectsIterator.cxx | 2 +- src/NIS/NIS_ObjectsIterator.hxx | 4 +-- 5 files changed, 48 insertions(+), 21 deletions(-) diff --git a/src/NIS/NIS_Drawer.cxx b/src/NIS/NIS_Drawer.cxx index e1d793c273..8c70653ac7 100755 --- a/src/NIS/NIS_Drawer.cxx +++ b/src/NIS/NIS_Drawer.cxx @@ -281,6 +281,8 @@ void NIS_Drawer::removeObject (const NIS_InteractiveObject * theObj, SetDynamicHilighted (Standard_False, theObj); if (myMapID.IsEmpty()) { UpdateExListId(NULL); + // Remove the drawer from context. + myCtx->myDrawers.Remove(this); } // Set Updated for the draw type. else if (theObj->IsHidden() == Standard_False && isUpdateViews) diff --git a/src/NIS/NIS_InteractiveContext.cxx b/src/NIS/NIS_InteractiveContext.cxx index 828dfcd21f..37b680644d 100755 --- a/src/NIS/NIS_InteractiveContext.cxx +++ b/src/NIS/NIS_InteractiveContext.cxx @@ -22,12 +22,14 @@ static void markAllDrawersUpdated (const NCollection_Map&); NIS_InteractiveContext::NIS_InteractiveContext () : myAllocator (new NIS_Allocator(1024*100)), + myLastObjectId (0), + myObjects (1000), // myDrawers (101, myAllocator), mySelectionMode (Mode_NoSelection), myIsShareDrawList (Standard_True) { // ID == 0 is invalid so we reserve this item from subsequent allocation. - myObjects.Append (NULL); + myObjects.SetValue(myLastObjectId, NULL); } //======================================================================= @@ -107,6 +109,22 @@ void NIS_InteractiveContext::DetachView (const Handle_NIS_View& theView) } } +//======================================================================= +//function : GetObject +//purpose : +//======================================================================= + +const Handle_NIS_InteractiveObject& NIS_InteractiveContext::GetObject + (const Standard_Integer theID) const +{ + if (!myObjects.IsBound(theID)) + { + static Handle_NIS_InteractiveObject aNull; + return aNull; + } + return myObjects(theID); +} + //======================================================================= //function : redraw //purpose : @@ -236,7 +254,8 @@ void NIS_InteractiveContext::Remove (const Handle_NIS_InteractiveObject& theObj, aDrawer->removeObject(theObj.operator->(), isUpdateViews); theObj->myID = 0; theObj->myDrawer.Nullify(); - myObjects(anID).Nullify(); + myObjects.UnsetValue(anID); + myMapNonSelectableObjects.Remove(anID); } } } @@ -249,7 +268,8 @@ void NIS_InteractiveContext::Remove (const Handle_NIS_InteractiveObject& theObj, void NIS_InteractiveContext::DisplayAll () { // UnHide all objects in the Context - NCollection_Vector ::Iterator anIter(myObjects); + NCollection_SparseArray ::ConstIterator + anIter(myObjects); for (; anIter.More(); anIter.Next()) { const Handle(NIS_InteractiveObject)& anObj = anIter.Value(); if (anObj.IsNull() == Standard_False) @@ -278,7 +298,8 @@ void NIS_InteractiveContext::DisplayAll () void NIS_InteractiveContext::EraseAll () { // Hide all objects in the Context - NCollection_Vector ::Iterator anIter(myObjects); + NCollection_SparseArray ::ConstIterator + anIter(myObjects); for (; anIter.More(); anIter.Next()) { const Handle(NIS_InteractiveObject)& anObj = anIter.Value(); if (anObj.IsNull() == Standard_False) { @@ -319,7 +340,8 @@ void NIS_InteractiveContext::EraseAll () void NIS_InteractiveContext::RemoveAll () { // Remove objects from the Context - NCollection_Vector ::Iterator anIter(myObjects); + NCollection_SparseArray ::Iterator + anIter(myObjects); for (; anIter.More(); anIter.Next()) { Handle(NIS_InteractiveObject)& anObj = anIter.ChangeValue(); if (anObj.IsNull() == Standard_False) { @@ -352,14 +374,13 @@ void NIS_InteractiveContext::RemoveAll () myAllocator->Reset(); myAllocator->ResetCounters(); - myDrawers.Clear(); - // Remove objects from maps myMapObjects[0].Clear(); myMapObjects[1].Clear(); myMapObjects[2].Clear(); myMapObjects[3].Clear(); myMapNonSelectableObjects.Clear(); + myObjects.Clear(); } //======================================================================= @@ -634,7 +655,7 @@ Standard_Real NIS_InteractiveContext::selectObject if (mySelectionMode != Mode_NoSelection || isOnlySel == Standard_False) { DetectedEnt anEnt; - NCollection_Vector ::Iterator + NCollection_SparseArray ::ConstIterator anIter(myObjects); for (; anIter.More(); anIter.Next()) { const Handle(NIS_InteractiveObject)& anObj = anIter.Value(); @@ -716,7 +737,7 @@ Standard_Boolean NIS_InteractiveContext::selectObjects { Standard_Boolean aResult (Standard_False); if (mySelectionMode != Mode_NoSelection) { - NCollection_Vector ::Iterator + NCollection_SparseArray ::ConstIterator anIter(myObjects); for (; anIter.More(); anIter.Next()) { const Handle(NIS_InteractiveObject)& anObj = anIter.Value(); @@ -758,7 +779,7 @@ Standard_Boolean NIS_InteractiveContext::selectObjects Standard_Boolean aResult (Standard_False); if (mySelectionMode != Mode_NoSelection) { - NCollection_Vector ::Iterator + NCollection_SparseArray ::ConstIterator anIter(myObjects); for (; anIter.More(); anIter.Next()) { @@ -894,8 +915,8 @@ void NIS_InteractiveContext::objectForDisplay Handle(NIS_InteractiveObject) anObj; theObj->Clone(myAllocator, anObj); theObj = anObj; - anObj->myID = myObjects.Length(); - myObjects.Append (anObj); + anObj->myID = ++myLastObjectId; + myObjects.SetValue (myLastObjectId, anObj); myMapObjects[theDrawType].Add(anObj->myID); anObj->myDrawType = theDrawType; } @@ -928,7 +949,7 @@ Handle_NIS_Allocator NIS_InteractiveContext::compactObjects() // Compact the memory: clone all objects to a new allocator, release // the old allocator instance. aNewAlloc = new NIS_Allocator; - NCollection_Vector::Iterator + NCollection_SparseArray::Iterator anIter(myObjects); for (; anIter.More(); anIter.Next()) { if (anIter.Value().IsNull() == Standard_False) { diff --git a/src/NIS/NIS_InteractiveContext.hxx b/src/NIS/NIS_InteractiveContext.hxx index 29b8360d3b..295726bc0a 100755 --- a/src/NIS/NIS_InteractiveContext.hxx +++ b/src/NIS/NIS_InteractiveContext.hxx @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -155,9 +155,8 @@ class NIS_InteractiveContext : public Standard_Transient /** * Query the InteractiveObject instance by its ID. */ - inline const Handle_NIS_InteractiveObject& - GetObject (const Standard_Integer theID) const - { return myObjects(theID); } + Standard_EXPORT const Handle_NIS_InteractiveObject& + GetObject (const Standard_Integer theID) const; /** * Query the total number of InteractiveObject instances. This number can be @@ -572,10 +571,15 @@ private: */ Handle_NIS_Allocator myAllocator; + /** + * The last added object ID. + */ + Standard_Integer myLastObjectId; /** * Container of InteractiveObject instances. */ - NCollection_Vector myObjects; + NCollection_SparseArray + myObjects; /** * List of Views. diff --git a/src/NIS/NIS_ObjectsIterator.cxx b/src/NIS/NIS_ObjectsIterator.cxx index b78527ce81..729425d124 100755 --- a/src/NIS/NIS_ObjectsIterator.cxx +++ b/src/NIS/NIS_ObjectsIterator.cxx @@ -16,7 +16,7 @@ void NIS_ObjectsIterator::Initialize (const Handle(NIS_InteractiveContext)& theCtx) { if (theCtx.IsNull()) - myIter = NCollection_Vector ::Iterator(); + myIter = NCollection_SparseArray ::Iterator(); else for (myIter.Init (theCtx->myObjects); myIter.More(); myIter.Next()) if (myIter.Value().IsNull() == Standard_False) diff --git a/src/NIS/NIS_ObjectsIterator.hxx b/src/NIS/NIS_ObjectsIterator.hxx index 58421de3d8..a324fa3e87 100755 --- a/src/NIS/NIS_ObjectsIterator.hxx +++ b/src/NIS/NIS_ObjectsIterator.hxx @@ -7,7 +7,7 @@ #ifndef NIS_ObjectsIterator_HeaderFile #define NIS_ObjectsIterator_HeaderFile -#include +#include #include class Handle_NIS_InteractiveContext; @@ -80,7 +80,7 @@ class NIS_ObjectsIterator protected: // ---------- PROTECTED FIELDS ---------- - NCollection_Vector ::Iterator myIter; + NCollection_SparseArray ::ConstIterator myIter; };