Fixed memory leaks when using syntactic language model.

This commit is contained in:
Lane Schwartz 2012-03-30 16:28:22 -04:00
parent c810902901
commit 6793fb9635
3 changed files with 9 additions and 11 deletions

View File

@ -29,7 +29,7 @@ namespace Moses
SyntacticLanguageModel::~SyntacticLanguageModel() {
VERBOSE(3,"Destructing SyntacticLanguageModel" << std::endl);
// delete m_files;
delete m_files;
}
size_t SyntacticLanguageModel::GetNumScoreComponents() const {
@ -86,10 +86,7 @@ namespace Moses
VERBOSE(3,"Evaluating SyntacticLanguageModel for a hypothesis" << endl);
const SyntacticLanguageModelState<YModel,XModel,S,R>& prev =
static_cast<const SyntacticLanguageModelState<YModel,XModel,S,R>&>(*prev_state);
const SyntacticLanguageModelState<YModel,XModel,S,R>* currentState = &prev;
SyntacticLanguageModelState<YModel,XModel,S,R>* tmpState = NULL;
SyntacticLanguageModelState<YModel,XModel,S,R>* nextState = NULL;
@ -103,10 +100,11 @@ namespace Moses
const std::string& string = factor->GetString();
if (i==0) {
nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>(&prev, string);
nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>((const SyntacticLanguageModelState<YModel,XModel,S,R>*)prev_state, string);
} else {
currentState = nextState;
nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>(currentState, string);
tmpState = nextState;
nextState = new SyntacticLanguageModelState<YModel,XModel,S,R>(tmpState, string);
delete tmpState;
}
double score = nextState->getScore();

View File

@ -69,8 +69,8 @@ template <class MH, class MO>
SyntacticLanguageModelFiles<MH,MO>::~SyntacticLanguageModelFiles() {
VERBOSE(3,"Destructing syntactic language model files" << std::endl);
//delete hiddenModel;
//delete observedModel;
delete hiddenModel;
delete observedModel;
}

View File

@ -27,7 +27,7 @@ template <class MY, class MX, class YS=typename MY::RandVarType, class B=NullBac
~SyntacticLanguageModelState() {
VERBOSE(3,"Destructing SyntacticLanguageModelState" << std::endl);
//delete randomVariableStore;
delete randomVariableStore;
}
virtual int Compare(const FFState& other) const;