diff --git a/src/NCollection/NCollection_BaseMap.hxx b/src/NCollection/NCollection_BaseMap.hxx index 41eac66863..ff6d5c81f7 100644 --- a/src/NCollection/NCollection_BaseMap.hxx +++ b/src/NCollection/NCollection_BaseMap.hxx @@ -245,6 +245,8 @@ public: NCollection_ListNode ** myData1; NCollection_ListNode ** myData2; + void resetSize() { mySize = 0; } + private: // ---------- PRIVATE FIELDS ------------ Standard_Integer myNbBuckets; diff --git a/src/NCollection/NCollection_Map.hxx b/src/NCollection/NCollection_Map.hxx index 1dd40bd46c..ac16df31fe 100644 --- a/src/NCollection/NCollection_Map.hxx +++ b/src/NCollection/NCollection_Map.hxx @@ -378,7 +378,7 @@ public: //! Clear data. If doReleaseMemory is false then the table of //! buckets is not released and will be reused. void Clear(const Standard_Boolean doReleaseMemory = Standard_False) - { Destroy (MapNode::delNode, doReleaseMemory); myFirst = myLast = nullptr; } + { Destroy (MapNode::delNode, doReleaseMemory); } //! Clear data and reset allocator void Clear (const Handle(NCollection_BaseAllocator)& theAllocator) @@ -388,6 +388,29 @@ public: NCollection_BaseAllocator::CommonBaseAllocator() ); } + //! Deallocate all node elements + void Destroy(NCollection_DelMapNode fDel, Standard_Boolean doReleaseMemory) + { + if (!IsEmpty()) + { + MapNode* aNode = myFirst; + while (aNode) + { + MapNode* aCurNode = aNode; + aNode = aNode->NextSeq(); + fDel (aCurNode, myAllocator); + } + myFirst = myLast = nullptr; + memset(myData1, 0, (NbBuckets() + 1) * sizeof(NCollection_ListNode*)); + resetSize(); + } + if (doReleaseMemory) + { + Standard::Free(myData1); + myData1 = myData2 = nullptr; + } + } + //! Destructor virtual ~NCollection_Map (void) { Clear(true); }