From fb498d8d40586c0d9c0cd65d66521ffca4f174c5 Mon Sep 17 00:00:00 2001 From: Hector Mendoza Date: Fri, 22 May 2015 20:13:44 -0600 Subject: [PATCH] Memory cleanup on object destruction. Appropriately release memory on object destruction. --- GLWidget.cpp | 3 +++ IconModelMgr.cpp | 11 ++++++++++- MainWindow.cpp | 18 ++++++++++++++++-- ToolMgr.cpp | 7 +++++++ TrackInfoWindow.cpp | 1 + VolumeTool.cpp | 1 + WorldObjectMgr.cpp | 8 ++++++++ 7 files changed, 46 insertions(+), 3 deletions(-) diff --git a/GLWidget.cpp b/GLWidget.cpp index 85725ba..98de63e 100644 --- a/GLWidget.cpp +++ b/GLWidget.cpp @@ -101,6 +101,9 @@ GLWidget::GLWidget(QWidget* parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), p GLWidget::~GLWidget() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { + delete mRenderTimer; + delete mFrameRateTimer; + delete atmosphere; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/IconModelMgr.cpp b/IconModelMgr.cpp index f79521c..1ee64e5 100644 --- a/IconModelMgr.cpp +++ b/IconModelMgr.cpp @@ -51,14 +51,23 @@ IconModelMgr::~IconModelMgr() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { mInstance = NULL; + int i = 0; + + //release icon/image data + for (i = 0; i < mIconList.size(); i++) + { + delete mIconList[i].image; + } + mIconList.clear(); #ifdef USING_ASSIMP //release model data - for (int i = 0; i < mModelList.size(); i++) + for (i = 0; i < mModelList.size(); i++) { const struct aiScene* scene = (const struct aiScene*)mModelList[i].modelData; aiReleaseImport(scene); } + mModelList.clear(); #endif } diff --git a/MainWindow.cpp b/MainWindow.cpp index 76571cd..3062506 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -87,7 +87,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi VolumeTool* volumeTool = new VolumeTool(mVolumeToolButton, mVolumeWindow); MeasuringTool* measuringTool = new MeasuringTool(mMeasuringToolButton, mMeasuringWindow); - toolMgr->addTool(pathTool); toolMgr->addTool(volumeTool); toolMgr->addTool(measuringTool); @@ -122,12 +121,27 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ /** - * Destructor. + * Destructor. Releases allocated memory. */ MainWindow::~MainWindow() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { delete ui; + delete mPathWindow; + delete mVolumeWindow; + delete mMeasuringWindow; + delete mPlacesWindow; + delete mTrackInfoWindow; + delete mPathVolumeWindow; + delete mAboutWindow; + delete mFileIO; + delete mShapefileReader; + + delete mViewModeToolButton; + delete mPathToolButton; + delete mVolumeToolButton; + delete mMeasuringToolButton; + mInstance = NULL; } diff --git a/ToolMgr.cpp b/ToolMgr.cpp index ca870f0..33ef3e6 100644 --- a/ToolMgr.cpp +++ b/ToolMgr.cpp @@ -42,6 +42,13 @@ ToolMgr::ToolMgr() ToolMgr::~ToolMgr() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { + //release all data + for (int i = 0; i < mToolList.size(); i++) + { + delete mToolList[i]; + } + mToolList.clear(); + mInstance = NULL; } diff --git a/TrackInfoWindow.cpp b/TrackInfoWindow.cpp index 7f8da5e..0d90576 100644 --- a/TrackInfoWindow.cpp +++ b/TrackInfoWindow.cpp @@ -52,6 +52,7 @@ TrackInfoWindow::~TrackInfoWindow() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { delete ui; + delete mUpdateTimer; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/VolumeTool.cpp b/VolumeTool.cpp index 2a4a1c8..c71a172 100644 --- a/VolumeTool.cpp +++ b/VolumeTool.cpp @@ -50,6 +50,7 @@ VolumeTool::VolumeTool(QToolButton* toolButton, QDialog* dialog) : Tool("Volume" VolumeTool::~VolumeTool() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { + delete mWorldObject; } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/WorldObjectMgr.cpp b/WorldObjectMgr.cpp index 7dbb8e1..dedeb5f 100644 --- a/WorldObjectMgr.cpp +++ b/WorldObjectMgr.cpp @@ -49,6 +49,14 @@ WorldObjectMgr::WorldObjectMgr() WorldObjectMgr::~WorldObjectMgr() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { + //release all object data + for (int i = 0; i < mWorldObjectList.size(); i++) + { + delete mWorldObjectList[i]; + } + mWorldObjectList.clear(); + delete mExpireTimer; + mInstance = NULL; }