diff --git a/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h b/Modules/Wrappers/ApplicationEngine/include/otbWrapperApplication.h index f33d1ba16869cdc0d3aa0f50d8226af0a76d7adf..7a499b8845912227e373ea1a00978787aaaca874 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 b420299ff6b707f8ccbed39577b488684e527fae..de1b2eec4a50724445e01b514c993bba276b4afc 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 fb90702544a20191e1f5a474c0c7571cb48015aa..95197325780aa501dc8edbcf5f41510988cf0299 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 89fca70c59c39ca00cbb67bfa515bee32f303403..10a685fba70146573f65c103b5a3cf570b038735 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 2790bdce255aa5d0e8a3f92ab625e274ce48bf10..623f55c84f2372b34df8ced749d53a69637312ac 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 cf70dc07b7bd8e50922a313f4bc6ff21ecaa973c..7b5caa5d0263529d606ecf87b7c774de3e25e953 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; }