From 028f504e56e0cd3b5f7cc8921327515887504c7b Mon Sep 17 00:00:00 2001 From: vsv Date: Tue, 31 Mar 2015 17:43:47 +0300 Subject: [PATCH] Free memory on deletion of handle object --- src/GeomAPI/GeomAPI_AISObject.cpp | 11 +++++++++++ src/GeomAPI/GeomAPI_AISObject.h | 2 ++ src/GeomAPI/GeomAPI_Interface.cpp | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 8f053f7cf..57d192bba 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -41,6 +41,17 @@ GeomAPI_AISObject::GeomAPI_AISObject() { } +GeomAPI_AISObject::~GeomAPI_AISObject() +{ + if (myImpl) { + // This is necessary for correct deletion of Handle entity. + // Without this Handle does not decremented counter to 0 + Handle(AIS_InteractiveObject) *anAIS = (Handle(AIS_InteractiveObject)*)myImpl; + anAIS->Nullify(); + } +} + + void GeomAPI_AISObject::createShape(std::shared_ptr theShape) { const TopoDS_Shape& aTDS = diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index ad879d1db..06bc2e905 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -28,6 +28,8 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface /// \brief Creation of empty AIS object GeomAPI_AISObject(); + ~GeomAPI_AISObject(); + /// \brief Creates AIS_Shape object using specified shape void createShape(std::shared_ptr theShape); diff --git a/src/GeomAPI/GeomAPI_Interface.cpp b/src/GeomAPI/GeomAPI_Interface.cpp index 1ee1a6213..4db15c996 100644 --- a/src/GeomAPI/GeomAPI_Interface.cpp +++ b/src/GeomAPI/GeomAPI_Interface.cpp @@ -18,8 +18,10 @@ GeomAPI_Interface::GeomAPI_Interface(void* theImpl) GeomAPI_Interface::~GeomAPI_Interface() { - if (myImpl) + if (myImpl) { delete myImpl; + myImpl = 0; + } } void GeomAPI_Interface::setImpl(void* theImpl) -- 2.39.2