diff options
author | siddharth jain <sija@microsoft.com> | 2020-11-04 14:02:48 +0300 |
---|---|---|
committer | siddharth jain <sija@microsoft.com> | 2020-11-04 14:02:48 +0300 |
commit | f40a77572333cbdb4aa18d70c2e8bdf74bba31e6 (patch) | |
tree | e7a6324571e3917fa96d70e563724f348e6729f6 | |
parent | 3cc2f4fde68dffee9904cbee4dc4910b38c3f530 (diff) |
changes to release memory
-rw-r--r-- | moses2/DLLEntryApi.cpp | 11 | ||||
-rw-r--r-- | moses2/Moses2Wrapper.cpp | 9 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp | 14 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTable.h | 2 | ||||
-rw-r--r-- | moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h | 4 |
5 files changed, 20 insertions, 20 deletions
diff --git a/moses2/DLLEntryApi.cpp b/moses2/DLLEntryApi.cpp index cb8def6c0..e6c785bb4 100644 --- a/moses2/DLLEntryApi.cpp +++ b/moses2/DLLEntryApi.cpp @@ -1,4 +1,5 @@ #include "Moses2Wrapper.h" +#include <iostream> using namespace std; using namespace Moses2; @@ -11,7 +12,7 @@ extern "C" __declspec(dllexport) int __stdcall GetMosesSystem(const char* filePa return 1; } -extern "C" __declspec(dllexport) int __stdcall MosesTranslate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char * output, int strlen) { +extern "C" __declspec(dllexport) int __stdcall MosesTranslate(Moses2::Moses2Wrapper * pObject, long id, const char* input, char* output, int strlen) { if (pObject != NULL) { std::string tr = pObject->Translate(input, id); @@ -23,11 +24,11 @@ extern "C" __declspec(dllexport) int __stdcall MosesTranslate(Moses2::Moses2Wrap return 0; } } -extern "C" __declspec(dllexport) int __stdcall ReleaseSystem(Moses2::Moses2Wrapper * pObject) { - if (pObject != NULL) +extern "C" __declspec(dllexport) int __stdcall ReleaseSystem(Moses2::Moses2Wrapper ** pObject) { + if (*pObject != NULL) { - delete pObject; - pObject = NULL; + delete *pObject; + *pObject = NULL; return 1; } else { diff --git a/moses2/Moses2Wrapper.cpp b/moses2/Moses2Wrapper.cpp index 8fa4a5156..01f1b6e72 100644 --- a/moses2/Moses2Wrapper.cpp +++ b/moses2/Moses2Wrapper.cpp @@ -14,11 +14,8 @@ namespace Moses2 { std::string translation = task.ReturnTranslation(); return translation; } - Moses2Wrapper* Moses2Wrapper::getInstance(const std::string& filePath) { - Moses2Wrapper *instance = new Moses2Wrapper(filePath); - return instance; - } Moses2Wrapper::~Moses2Wrapper() { - cout << "Destructor is called "; - } + delete m_param; + delete m_system; + } }
\ No newline at end of file diff --git a/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp index 0a74fcaa3..a37f5b778 100644 --- a/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.cpp @@ -36,7 +36,7 @@ using namespace std; namespace Moses2 { -thread_local DynamicPhraseTable::PBNODE * DynamicPhraseTable::m_rootPb; +thread_local DynamicPhraseTable::PBNODE DynamicPhraseTable::m_rootPb; //////////////////////////////////////////////////////////////////////// @@ -48,7 +48,7 @@ DynamicPhraseTable::DynamicPhraseTable(size_t startInd, const std::string &line) DynamicPhraseTable::~DynamicPhraseTable() { - delete m_rootPb; + //delete m_rootPb; } void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseTableString) @@ -60,7 +60,7 @@ void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseT MemPool tmpSourcePool; if (system.isPb) { - m_rootPb = new PBNODE(); + //m_rootPb = new PBNODE(); } else { abort(); //cerr << "m_rootSCFG=" << m_rootSCFG << endl; @@ -104,7 +104,7 @@ void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseT system.featureFunctions.EvaluateInIsolation(pool, system, *source, *target); //cerr << "EvaluateInIsolation:" << target->Debug(system) << endl; - m_rootPb->AddRule(m_input, *source, target); + m_rootPb.AddRule(m_input, *source, target); //cerr << "target=" << target->Debug(system) << endl; } else { @@ -113,7 +113,7 @@ void DynamicPhraseTable::CreatePTForInput(const ManagerBase &mgr, string phraseT } if (system.isPb) { - m_rootPb->SortAndPrune(m_tableLimit, pool, system); + m_rootPb.SortAndPrune(m_tableLimit, pool, system); //cerr << "root=" << &m_rootPb << endl; } else { abort(); @@ -139,12 +139,12 @@ TargetPhrases* DynamicPhraseTable::Lookup(const Manager &mgr, MemPool &pool, InputPath &inputPath) const { const SubPhrase<Moses2::Word> &phrase = inputPath.subPhrase; - TargetPhrases *tps = m_rootPb->Find(m_input, phrase); + TargetPhrases *tps = m_rootPb.Find(m_input, phrase); return tps; } void DynamicPhraseTable::CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const { - delete m_rootPb; + m_rootPb.CleanNode(); //TODO : clean this } void DynamicPhraseTable::InitActiveChart( diff --git a/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h index 7fd467700..99588eda8 100644 --- a/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTable.h @@ -69,7 +69,7 @@ public: virtual void CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const; protected: - thread_local static PBNODE *m_rootPb; + thread_local static PBNODE m_rootPb; void LookupGivenNode( MemPool &pool, diff --git a/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h b/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h index b10e4e161..56eb181cb 100644 --- a/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h +++ b/moses2/TranslationModel/Dynamic/DynamicPhraseTableNode.h @@ -88,7 +88,9 @@ public: delete m_unsortedTPS; } } - + void CleanNode() { + m_children.clear(); + } const Children &GetChildren() const { return m_children; } |