From bf95447514333e8f9f9ee167d580b2877dae521f Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 20 Oct 2016 16:26:25 +0300 Subject: [PATCH] 0027604: Application Framework - memory is not released after closing XBF file Virtual method *BinLDrivers_DocumentRetrievalDriver::Clear* now allows to Clear a cash data accumulated during a reading. So, in successor class BinDrivers_DocumentRetrievalDriver this allows clearing the BinMNaming_NamedShapeDriver set of stored shapes when it is not needed anymore. --- .../BinDrivers_DocumentRetrievalDriver.cxx | 17 ++++++++ .../BinDrivers_DocumentRetrievalDriver.hxx | 3 ++ .../BinLDrivers_DocumentRetrievalDriver.cxx | 15 +++++-- .../BinLDrivers_DocumentRetrievalDriver.hxx | 8 +++- tests/bugs/caf/bug27604 | 39 +++++++++++++++++++ 5 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 tests/bugs/caf/bug27604 diff --git a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx index f953dbc89c..69d0a444f4 100644 --- a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.cxx @@ -90,6 +90,23 @@ void BinDrivers_DocumentRetrievalDriver::CheckShapeSection( Standard_IStream& /*IS*/) {} +//======================================================================= +//function : Clear +//purpose : +//======================================================================= +void BinDrivers_DocumentRetrievalDriver::Clear() +{ + // Clear NamedShape driver + Handle(BinMDF_ADriver) aDriver; + if (myDrivers->GetDriver(STANDARD_TYPE(TNaming_NamedShape), aDriver)) + { + Handle(BinMNaming_NamedShapeDriver) aNamedShapeDriver = + Handle(BinMNaming_NamedShapeDriver)::DownCast(aDriver); + aNamedShapeDriver->Clear(); + } + BinLDrivers_DocumentRetrievalDriver::Clear(); +} + //======================================================================= //function : PropagateDocumentVersion //purpose : diff --git a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.hxx b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.hxx index 97e751df04..4691634aee 100644 --- a/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.hxx +++ b/src/BinDrivers/BinDrivers_DocumentRetrievalDriver.hxx @@ -47,6 +47,9 @@ public: Standard_EXPORT virtual void ReadShapeSection (BinLDrivers_DocumentSection& theSection, Standard_IStream& theIS, const Standard_Boolean isMess = Standard_False) Standard_OVERRIDE; Standard_EXPORT virtual void CheckShapeSection (const Storage_Position& thePos, Standard_IStream& theIS) Standard_OVERRIDE; + + //! Clears the NamedShape driver + Standard_EXPORT virtual void Clear() Standard_OVERRIDE; Standard_EXPORT virtual void PropagateDocumentVersion (const Standard_Integer theVersion) Standard_OVERRIDE; diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx index aa851d9cba..cd519df753 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.cxx @@ -297,9 +297,7 @@ void BinLDrivers_DocumentRetrievalDriver::Read (Standard_IStream& // read sub-tree of the root label Standard_Integer nbRead = ReadSubTree (theIStream, aData->Root()); - myPAtt.Destroy(); // free buffer - myRelocTable.Clear(); - myMapUnsupported.Clear(); + Clear(); if (nbRead > 0) { // attach data to the document @@ -491,6 +489,17 @@ void BinLDrivers_DocumentRetrievalDriver::CheckShapeSection( } } +//======================================================================= +//function : Clear +//purpose : +//======================================================================= +void BinLDrivers_DocumentRetrievalDriver::Clear() +{ + myPAtt.Destroy(); // free buffer + myRelocTable.Clear(); + myMapUnsupported.Clear(); +} + //======================================================================= //function : PropagateDocumentVersion //purpose : diff --git a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx index 97afb49c19..bf0294b65e 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx +++ b/src/BinLDrivers/BinLDrivers_DocumentRetrievalDriver.hxx @@ -83,10 +83,16 @@ protected: //! define the procedure of reading a section to file. Standard_EXPORT virtual void ReadSection (BinLDrivers_DocumentSection& theSection, const Handle(CDM_Document)& theDoc, Standard_IStream& theIS); + //! define the procedure of reading a shapes section to file. Standard_EXPORT virtual void ReadShapeSection (BinLDrivers_DocumentSection& theSection, Standard_IStream& theIS, const Standard_Boolean isMess = Standard_False); + //! checks the shapes section can be correctly retreived. Standard_EXPORT virtual void CheckShapeSection (const Storage_Position& thePos, Standard_IStream& theIS); - + + //! clears the reading-cash data in drivers if any. + Standard_EXPORT virtual void Clear(); + + //! provides the version of document to all drivers Standard_EXPORT virtual void PropagateDocumentVersion (const Standard_Integer theVersion); //! Check a file version(in which file was written) with a current version. diff --git a/tests/bugs/caf/bug27604 b/tests/bugs/caf/bug27604 new file mode 100644 index 0000000000..8d2806b421 --- /dev/null +++ b/tests/bugs/caf/bug27604 @@ -0,0 +1,39 @@ +puts "========" +puts "OCC27604" +puts "Application Framework - memory is not released after closing XBF file" +puts "========" +puts "" + +set aBigShape Bottom.brep + +pload OCAF MODELING + +# just a big shape to fit in memory +restore [locate_data_file $aBigShape] s + +# store it in the document +NewDocument D BinOcaf +SetShape D "0:2" s +SaveAs D test.cbf +Close D + +# store the memory used before opening a document +set aBefore [meminfo h] + +Open test.cbf DD +set aDocLoaded [meminfo h] +set aBigDelta [expr $aDocLoaded - $aBefore] +Close DD + +set anAfter [meminfo h] +set aDelta [expr $anAfter - $aBefore] + +puts "Memory used before: $aBefore" +puts "After open: $aDocLoaded" +puts "After close: $anAfter" + +# if after the close the memory used left 5% more than before closed, this is an issue +# (less 5% is the measurement tolerance) +if {[expr $aBigDelta / 20. - $aDelta] < 0} { + puts "Error: the memory is not freed after Open/Close" +} -- 2.20.1