From 4c0d97ac4271a314545d222be1f1d17008e8a7c3 Mon Sep 17 00:00:00 2001 From: vpa Date: Wed, 30 Mar 2016 18:06:52 +0300 Subject: [PATCH] 0027318: Memory is not released in Select3D_SensitiveSet when destroying AIS_InteractiveContext without removing objects - destructor was added to SelectMgr_SelectableObject to clean up selections; - test case for issue #27318 Warnings elimination --- src/QABugs/QABugs_19.cxx | 26 ++++++++++++++- src/SelectMgr/SelectMgr_SelectableObject.cxx | 11 ++++++ src/SelectMgr/SelectMgr_SelectableObject.hxx | 2 ++ tests/bugs/vis/bug27318 | 35 ++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/bugs/vis/bug27318 diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index faa0efce72..7bc686dfd5 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -5140,6 +5140,26 @@ static Standard_Integer OCC27065(Draw_Interpretor& di, return 0; } +//======================================================================== +//function : OCC27318 +//purpose : Creates a box that is not listed in map of AIS objects of ViewerTest +//======================================================================== +static Standard_Integer OCC27318 (Draw_Interpretor& /*theDI*/, Standard_Integer /*theArgc*/, const char** theArgv) +{ + const Handle(AIS_InteractiveContext)& aCtx = ViewerTest::GetAISContext(); + if (aCtx.IsNull()) + { + std::cout << "No interactive context. Use 'vinit' command before " << theArgv[0] << "\n"; + return 1; + } + + TopoDS_Shape aBox = BRepPrimAPI_MakeBox (20, 20, 20).Shape(); + Handle(AIS_Shape) aBoxObj = new AIS_Shape (aBox); + aCtx->Display (aBoxObj, Standard_True); + + return 0; +} + void QABugs::Commands_19(Draw_Interpretor& theCommands) { const char *group = "QABugs"; @@ -5253,6 +5273,10 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) { theCommands.Add ("OCC27065", "OCC27065 spine profile", __FILE__, OCC27065, group); - + + theCommands.Add ("OCC27318", + "OCC27318: Creates a box that is not listed in map of AIS objects of ViewerTest", + __FILE__, OCC27318, group); + return; } diff --git a/src/SelectMgr/SelectMgr_SelectableObject.cxx b/src/SelectMgr/SelectMgr_SelectableObject.cxx index 6a96a331bb..bb6260d212 100644 --- a/src/SelectMgr/SelectMgr_SelectableObject.cxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.cxx @@ -69,6 +69,17 @@ SelectMgr_SelectableObject::SelectMgr_SelectableObject (const PrsMgr_TypeOfPrese myHilightDrawer->Link (myDrawer); } +//================================================== +// Function: Destructor +// Purpose : Clears all selections of the object +//================================================== +SelectMgr_SelectableObject::~SelectMgr_SelectableObject() +{ + for (Standard_Integer aSelIdx = 1; aSelIdx <= myselections.Length(); ++aSelIdx) + { + myselections.Value (aSelIdx)->Clear(); + } +} //================================================== // Function: HasSelection diff --git a/src/SelectMgr/SelectMgr_SelectableObject.hxx b/src/SelectMgr/SelectMgr_SelectableObject.hxx index f7b8e7e740..4968243315 100644 --- a/src/SelectMgr/SelectMgr_SelectableObject.hxx +++ b/src/SelectMgr/SelectMgr_SelectableObject.hxx @@ -56,6 +56,8 @@ class SelectMgr_SelectableObject : public PrsMgr_PresentableObject public: + //! Clears all selections of the object + Standard_EXPORT virtual ~SelectMgr_SelectableObject(); //! Recovers and calculates any sensitive primitive, //! aSelection, available in Shape mode, specified by diff --git a/tests/bugs/vis/bug27318 b/tests/bugs/vis/bug27318 new file mode 100644 index 0000000000..45da40a8f0 --- /dev/null +++ b/tests/bugs/vis/bug27318 @@ -0,0 +1,35 @@ +puts "========" +puts "OCC27318" +puts "========" +puts "" +################################################################## +puts "Memory is not released in Select3D_SensitiveSet when destroying AIS_InteractiveContext without removing objects" +################################################################## + +pload VISUALIZATION QAcommands + +# to measure initial memory correctly, open and close interactive context +# to load FreeImage +vinit +vclose +set aMemInit [meminfo h] +puts "Initial mem: [expr $aMemInit / (1024 * 1024)] MiB ([expr $aMemInit])" + +# create a box and display it in each interactive context. The context is +# the only instance that references to the box. Therefore, the box must be +# removed completely after each context's closing +for {set anIter 0} {$anIter < 300} {incr anIter} { + vinit + OCC27318 + vclose +} + +set aMemAfter [meminfo h] +puts "Memory after closing interactive context several times: [expr $aMemAfter / (1024 * 1024)] MiB ([expr $aMemAfter])" + +set aRatio [expr $aMemAfter / double($aMemInit)] + +# check if the memory difference is greater than 5% +if [expr $aRatio > 1.05] { + puts "Error : TEST FAILED" +}