mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Memory Management : Adjustment and fixes
Add release of several static singleton objects Fix several minor memory leaks
This commit is contained in:
@@ -68,9 +68,9 @@ endif()
|
||||
# Defining all the source (and header) files
|
||||
# ##############################################################################
|
||||
|
||||
set(CODE_HEADER_FILES)
|
||||
set(CODE_HEADER_FILES RiaMainTools.h)
|
||||
|
||||
set(CODE_SOURCE_FILES RiaMain.cpp)
|
||||
set(CODE_SOURCE_FILES RiaMain.cpp RiaMainTools.cpp)
|
||||
|
||||
if(RESINSIGHT_ENABLE_GRPC)
|
||||
list(APPEND CODE_HEAD_FILES RiaGrpcConsoleApplication.h
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RiaArgumentParser.h"
|
||||
#include "RiaLogging.h"
|
||||
#include "RiaMainTools.h"
|
||||
|
||||
#ifdef ENABLE_GRPC
|
||||
#include "RiaGrpcConsoleApplication.h"
|
||||
@@ -26,6 +27,7 @@
|
||||
#include "RiaConsoleApplication.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#endif
|
||||
|
||||
#include "cvfProgramOptions.h"
|
||||
#include "cvfqtUtils.h"
|
||||
|
||||
@@ -66,8 +68,12 @@ int main( int argc, char* argv[] )
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
// Global initialization
|
||||
RiaLogging::loggerInstance()->setLevel( int( RILogLevel::RI_LL_DEBUG ) );
|
||||
|
||||
// Create feature manager before the application object is created
|
||||
RiaMainTools::initializeSingletons();
|
||||
|
||||
std::unique_ptr<RiaApplication> app( createApplication( argc, argv ) );
|
||||
|
||||
cvf::ProgramOptions progOpt;
|
||||
@@ -112,6 +118,9 @@ int main( int argc, char* argv[] )
|
||||
// Make sure project is closed to avoid assert and crash in destruction of widgets
|
||||
app->closeProject();
|
||||
|
||||
app.reset();
|
||||
RiaMainTools::releaseSingletonAndFactoryObjects();
|
||||
|
||||
return 0;
|
||||
}
|
||||
else if ( status == RiaApplication::ApplicationStatus::EXIT_WITH_ERROR )
|
||||
@@ -147,6 +156,9 @@ int main( int argc, char* argv[] )
|
||||
throw;
|
||||
}
|
||||
|
||||
app.reset();
|
||||
RiaMainTools::releaseSingletonAndFactoryObjects();
|
||||
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
|
||||
61
ApplicationExeCode/RiaMainTools.cpp
Normal file
61
ApplicationExeCode/RiaMainTools.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RiaMainTools.h"
|
||||
#include "RiaRegressionTestRunner.h"
|
||||
#include "RiaSocketCommand.h"
|
||||
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafCmdFeatureManager.h"
|
||||
#include "cafPdmDefaultObjectFactory.h"
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMainTools::initializeSingletons()
|
||||
{
|
||||
caf::CmdFeatureManager::createSingleton();
|
||||
RiaRegressionTestRunner::createSingleton();
|
||||
caf::PdmDefaultObjectFactory::createSingleton();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// This method is used to release memory allocated by static functions. This enables use of memory allocation tools
|
||||
/// after the application has closed down.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiaMainTools::releaseSingletonAndFactoryObjects()
|
||||
{
|
||||
caf::CmdFeatureManager::deleteSingleton();
|
||||
RiaRegressionTestRunner::deleteSingleton();
|
||||
caf::PdmDefaultObjectFactory::deleteSingleton();
|
||||
|
||||
{
|
||||
auto factory = caf::Factory<caf::PdmUiFieldEditorHandle, QString>::instance();
|
||||
factory->deleteCreatorObjects();
|
||||
}
|
||||
|
||||
{
|
||||
auto factory = caf::Factory<caf::CmdFeature, std::string>::instance();
|
||||
factory->deleteCreatorObjects();
|
||||
}
|
||||
{
|
||||
auto factory = caf::Factory<RiaSocketCommand, QString>::instance();
|
||||
factory->deleteCreatorObjects();
|
||||
}
|
||||
}
|
||||
25
ApplicationExeCode/RiaMainTools.h
Normal file
25
ApplicationExeCode/RiaMainTools.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2022 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
class RiaMainTools
|
||||
{
|
||||
public:
|
||||
static void initializeSingletons();
|
||||
static void releaseSingletonAndFactoryObjects();
|
||||
};
|
||||
Reference in New Issue
Block a user