From 896555a41253f2d30c4bce4ac38de283a152597c Mon Sep 17 00:00:00 2001 From: Antoine Regimbeau <antoine.regimbeau@c-s.fr> Date: Tue, 6 Feb 2018 16:13:29 +0100 Subject: [PATCH] BUG: cleaning memory of output parameter, input parameter and watchers --- .../include/otbWrapperApplication.h | 4 ++ .../include/otbWrapperOutputImageParameter.h | 2 + .../otbWrapperOutputVectorDataParameter.h | 7 +++ .../src/otbWrapperApplication.cxx | 53 ++++++++++++++++++- .../src/otbWrapperOutputImageParameter.cxx | 32 +++++++++++ .../src/otbWrapperCommandLineLauncher.cxx | 4 +- 6 files changed, 100 insertions(+), 2 deletions(-) diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index f33d1ba168..7a499b8845 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h @@ -154,6 +154,10 @@ public: */ int ExecuteAndWriteOutput(); + /** Clear the pipeline and the various parameters that hold data + */ + virtual void ClearMemory(); + /* Get the internal application parameters * * WARNING: this method may disappear from the API */ diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h index b420299ff6..de1b2eec4a 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputImageParameter.h @@ -113,6 +113,8 @@ public: std::string CheckFileName(bool fixMissingExtension = false); + void ClearValue() override; + protected: /** Constructor */ OutputImageParameter(); diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputVectorDataParameter.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputVectorDataParameter.h index fb90702544..9519732578 100644 --- a/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputVectorDataParameter.h +++ b/Modules/Wrappers/ApplicationEngine/include/otbWrapperOutputVectorDataParameter.h @@ -107,6 +107,13 @@ public: m_Writer = otb::VectorDataFileWriter<VectorDataType>::New(); } + void ClearValue() override + { + m_Writer = nullptr; + m_VectorData = nullptr; + m_FileName = ""; + Superclass::ClearValue(); + } protected: /** Constructor */ OutputVectorDataParameter() diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx index 89fca70c59..10a685fba7 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperApplication.cxx @@ -469,6 +469,7 @@ int Application::ExecuteAndWriteOutput() std::cout<<"Add Process and write"<<std::endl; AddProcess(outputParam->GetWriter(), progressId.str()); outputParam->Write(); + // ClearWriter in param(); } } else if (GetParameterType(key) == ParameterType_OutputVectorData @@ -520,12 +521,62 @@ int Application::ExecuteAndWriteOutput() } this->AfterExecuteAndWriteOutputs(); - m_Filters.clear(); m_Chrono.Stop(); + ClearMemory(); return status; } +void Application::ClearMemory() +{ + // Cleaning the parameter input and output + std::vector<std::string> paramList = GetParametersKeys(true); + for (std::vector<std::string>::const_iterator it = paramList.begin(); + it != paramList.end(); + ++it) + { + std::string key = *it; + if (GetParameterType(key) == ParameterType_InputImage ) + { + Parameter* param = GetParameterByKey(key); + InputImageParameter * input = dynamic_cast<InputImageParameter*>(param); + input->ClearValue(); + } + else if (GetParameterType(key) == ParameterType_InputImageList ) + { + Parameter* param = GetParameterByKey(key); + InputImageListParameter * input = dynamic_cast<InputImageListParameter*>(param); + input->ClearValue(); + } + else if (GetParameterType(key) == ParameterType_InputVectorData ) + { + Parameter* param = GetParameterByKey(key); + InputVectorDataParameter * input = dynamic_cast<InputVectorDataParameter*>(param); + input->ClearValue(); + } + else if (GetParameterType(key) == ParameterType_InputVectorDataList ) + { + Parameter* param = GetParameterByKey(key); + InputVectorDataListParameter * input = dynamic_cast<InputVectorDataListParameter*>(param); + input->ClearValue(); + } + else if (GetParameterType(key) == ParameterType_OutputImage ) + { + Parameter* param = GetParameterByKey(key); + OutputImageParameter * input = dynamic_cast<OutputImageParameter*>(param); + input->ClearValue(); + } + else + { + continue; + } + } + // Cleaning m_ProgressSource + m_ProgressSource = nullptr; + + // Cleaning m_Filters + m_Filters.clear(); +} /* Enable the use of an optional parameter. Returns the previous state */ void Application::EnableParameter(std::string paramKey) { diff --git a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx index 2790bdce25..623f55c84f 100644 --- a/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx +++ b/Modules/Wrappers/ApplicationEngine/src/otbWrapperOutputImageParameter.cxx @@ -449,6 +449,9 @@ OutputImageParameter::Write() { itkExceptionMacro("Unknown image type"); } + + // Clear writer + m_UInt8Writer = nullptr; } @@ -625,5 +628,34 @@ OutputImageParameter::CheckFileName(bool fixMissingExtension) return ret; } +void OutputImageParameter::ClearValue() +{ + m_Image = nullptr; + m_FileName = ""; + + m_UInt8Writer = nullptr; + m_Int16Writer = nullptr; + m_UInt16Writer = nullptr; + m_Int32Writer = nullptr; + m_UInt32Writer = nullptr; + m_FloatWriter = nullptr; + m_DoubleWriter = nullptr; + + m_VectorUInt8Writer = nullptr; + m_VectorInt16Writer = nullptr; + m_VectorUInt16Writer = nullptr; + m_VectorInt32Writer = nullptr; + m_VectorUInt32Writer = nullptr; + m_VectorFloatWriter = nullptr; + m_VectorDoubleWriter = nullptr; + + m_RGBUInt8Writer = nullptr; + m_RGBAUInt8Writer = nullptr; + + m_RAMValue = 0; + + Superclass::ClearValue(); +} + } } diff --git a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx index cf70dc07b7..7b5caa5d02 100644 --- a/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx +++ b/Modules/Wrappers/CommandLine/src/otbWrapperCommandLineLauncher.cxx @@ -188,7 +188,9 @@ bool CommandLineLauncher::ExecuteAndWriteOutput() m_Application->GetLogger()->Fatal("Caught unknown exception during application execution.\n"); return false; } - + + // Cleaning process + DeleteWatcherList(); return true; } -- GitLab