@@ -660,45 +660,59 @@ void BOPAlgo_PaveFiller::MakeBlocks(const Message_ProgressRange& theRange)
660660 return ;
661661 }
662662 //
663- bool bExist, bValid2D;
664- int i, nF1, nF2, aNbC, aNbP, j;
665- int nV1, nV2;
666- double aT1, aT2;
663+ bool bExist, bValid2D;
664+ int i, nF1, nF2, aNbC, aNbP, j;
665+ int nV1, nV2;
666+ double aT1, aT2;
667+ // Main allocator for cross-iteration data (IncAllocator for performance)
667668 occ::handle<NCollection_BaseAllocator> aAllocator = new NCollection_IncAllocator;
668669 // Temporary allocator for per-iteration collections that are cleared each iteration.
669- // Using separate allocator allows to reclaim memory via Reset(false) at the start
670- // of each iteration, preventing memory accumulation in the main loop .
670+ // Using separate allocator allows memory reuse via Reset(false) at each iteration.
671+ // Collections are kept outside the loop to reuse their bucket arrays after Clear() .
671672 occ::handle<NCollection_IncAllocator> aTmpAllocator = new NCollection_IncAllocator;
673+ // Default allocator for collections that require proper Free() behavior (Remove/UnBind).
674+ // IncAllocator::Free() is a no-op, so collections with Remove/UnBind must use default.
675+ occ::handle<NCollection_BaseAllocator> aDefaultAllocator =
676+ NCollection_BaseAllocator::CommonBaseAllocator ();
672677 NCollection_List<occ::handle<BOPDS_PaveBlock>>::Iterator aItLPB;
673678 TopoDS_Edge aES;
674679 occ::handle<BOPDS_PaveBlock> aPBOut;
675680 //
676681 // -----------------------------------------------------scope f
677682 //
678- // Per-iteration collections (use temporary allocator, reset each iteration)
679- NCollection_List<int > aLSE (aTmpAllocator), aLBV (aTmpAllocator);
680- NCollection_Map<int > aMVOnIn (100 , aTmpAllocator), aMVCommon (100 , aTmpAllocator),
681- aMVStick (100 , aTmpAllocator), aMVEF (100 , aTmpAllocator), aMVBounds (100 , aTmpAllocator);
683+ // Per-iteration collections (use temporary allocator, cleared and reset each iteration).
684+ // Kept outside loop to reuse bucket arrays - Clear() preserves allocated buckets.
685+ NCollection_List<int > aLSE (aTmpAllocator);
686+ NCollection_List<int > aLBV (aTmpAllocator);
687+ NCollection_Map<int > aMVOnIn (100 , aTmpAllocator);
688+ NCollection_Map<int > aMVCommon (100 , aTmpAllocator);
689+ NCollection_Map<int > aMVStick (100 , aTmpAllocator);
690+ NCollection_Map<int > aMVEF (100 , aTmpAllocator);
691+ NCollection_Map<int > aMVBounds (100 , aTmpAllocator);
692+ NCollection_Map<int > aMI (100 , aTmpAllocator);
682693 NCollection_IndexedMap<occ::handle<BOPDS_PaveBlock>> aMPBOnIn (100 , aTmpAllocator);
683- NCollection_Map<occ::handle<BOPDS_PaveBlock>> aMPBCommon;
684- NCollection_DataMap<int , double > aMVTol (100 , aTmpAllocator);
694+ NCollection_Map<occ::handle<BOPDS_PaveBlock>> aMPBCommon (100 , aTmpAllocator);
685695 NCollection_DataMap<int , NCollection_List<int >> aDMBV (100 , aTmpAllocator);
696+ // aMVTol has UnBind() operations - must use default allocator for proper Free()
697+ NCollection_DataMap<int , double > aMVTol (100 , aDefaultAllocator);
698+ //
686699 // Cross-iteration collections (use main allocator, persist through entire loop)
687- NCollection_Map<int > aMI (100 , aAllocator);
688- NCollection_Map<occ::handle<BOPDS_PaveBlock>> aMPBAdd ( 100 , aAllocator);
689- NCollection_List<occ::handle<BOPDS_PaveBlock>> aLPB (aAllocator );
700+ NCollection_Map<occ::handle<BOPDS_PaveBlock>> aMPBAdd (100 , aAllocator);
701+ // aLPB has Remove() operations - must use default allocator for proper Free()
702+ NCollection_List<occ::handle<BOPDS_PaveBlock>> aLPB (aDefaultAllocator );
690703 NCollection_IndexedDataMap<TopoDS_Shape, BOPDS_CoupleOfPaveBlocks, TopTools_ShapeMapHasher>
691704 aMSCPB (100 , aAllocator);
692705 NCollection_DataMap<TopoDS_Shape, int , TopTools_ShapeMapHasher> aMVI (100 , aAllocator);
693706 NCollection_DataMap<occ::handle<BOPDS_PaveBlock>, NCollection_List<occ::handle<BOPDS_PaveBlock>>>
694- aDMExEdges (100 , aAllocator);
695- NCollection_DataMap<int , int > aDMNewSD (100 , aAllocator);
696- NCollection_DataMap<int , NCollection_List<int >> aDMVLV;
707+ aDMExEdges (100 , aAllocator);
708+ NCollection_DataMap<int , int > aDMNewSD (100 , aAllocator);
709+ // aDMVLV has UnBind() operations - must use default allocator for proper Free()
710+ NCollection_DataMap<int , NCollection_List<int >> aDMVLV (100 , aDefaultAllocator);
697711 NCollection_DataMap<int , double >::Iterator aItMV;
698712 NCollection_IndexedMap<occ::handle<BOPDS_PaveBlock>> aMicroPB (100 , aAllocator);
699- NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aVertsOnRejectedPB;
713+ NCollection_IndexedMap<TopoDS_Shape, TopTools_ShapeMapHasher> aVertsOnRejectedPB ( 100 , aAllocator) ;
700714 // Map of PaveBlocks with the faces to which it has to be added
701- BOPAlgo_DataMapOfPaveBlockListOfInteger aPBFacesMap;
715+ BOPAlgo_DataMapOfPaveBlockListOfInteger aPBFacesMap ( 100 , aAllocator) ;
702716 //
703717 // The vector aFFToRecheck contains indices of potentially problematic Face-Face intersections
704718 NCollection_Vector<int > aFFToRecheck;
@@ -736,6 +750,7 @@ void BOPAlgo_PaveFiller::MakeBlocks(const Message_ProgressRange& theRange)
736750 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo (nF1);
737751 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo (nF2);
738752 //
753+ // Clear per-iteration collections and reset allocator for memory reuse
739754 aMVOnIn.Clear ();
740755 aMVCommon.Clear ();
741756 aMPBOnIn.Clear ();
@@ -747,6 +762,7 @@ void BOPAlgo_PaveFiller::MakeBlocks(const Message_ProgressRange& theRange)
747762 aMVStick.Clear ();
748763 aMVEF.Clear ();
749764 aMVBounds.Clear ();
765+ aMI.Clear ();
750766 aTmpAllocator->Reset (false );
751767 //
752768 myDS->SubShapesOnIn (nF1, nF2, aMVOnIn, aMVCommon, aMPBOnIn, aMPBCommon);
@@ -1104,15 +1120,6 @@ void BOPAlgo_PaveFiller::MakeBlocks(const Message_ProgressRange& theRange)
11041120 // into all faces, not participated in creation of that edge, as IN edge
11051121
11061122 PutSEInOtherFaces (aPSOuter.Next ());
1107- //
1108- // -----------------------------------------------------scope t
1109- aMVStick.Clear ();
1110- aMPBOnIn.Clear ();
1111- aMVOnIn.Clear ();
1112- aMVCommon.Clear ();
1113- aDMExEdges.Clear ();
1114- aMI.Clear ();
1115- aDMNewSD.Clear ();
11161123}
11171124
11181125// =================================================================================================
0 commit comments