- Fixed a minor memory leak in LanguageKenLM

- Used boost as a workaround for a bigger leak in PhraseDictionaryTree
  (dynamic allocation in a static function)


git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/augmLMResult@4137 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
mlegendr 2011-08-09 14:43:27 +00:00
parent fca5efdb0b
commit 5c773376d3
2 changed files with 11 additions and 7 deletions

View File

@ -127,12 +127,14 @@ template <class Model> void LanguageModelKen<Model>::TranslateIDs(const std::vec
} }
template <class Model> LanguageModelKen<Model>::LanguageModelKen(bool lazy) template <class Model> LanguageModelKen<Model>::LanguageModelKen(bool lazy)
:m_ngram(NULL), m_lazy(lazy) :m_ngram(NULL), m_lazy(lazy), m_nullContextState(NULL), m_beginSentenceState(NULL)
{ {
} }
template <class Model> LanguageModelKen<Model>::~LanguageModelKen() template <class Model> LanguageModelKen<Model>::~LanguageModelKen()
{ {
delete m_nullContextState;
delete m_beginSentenceState;
delete m_ngram; delete m_ngram;
} }

View File

@ -1,5 +1,6 @@
// $Id$ // $Id$
// vim:tabstop=2 // vim:tabstop=2
#include <boost/shared_ptr.hpp>
#include "PhraseDictionaryTree.h" #include "PhraseDictionaryTree.h"
#include <map> #include <map>
#include <cassert> #include <cassert>
@ -121,18 +122,19 @@ typedef LVoc<std::string> WordVoc;
static WordVoc* ReadVoc(const std::string& filename) static WordVoc* ReadVoc(const std::string& filename)
{ {
static std::map<std::string,WordVoc*> vocs; static std::map<std::string,boost::shared_ptr<WordVoc> > vocs;
#ifdef WITH_THREADS #ifdef WITH_THREADS
boost::mutex mutex; boost::mutex mutex;
boost::mutex::scoped_lock lock(mutex); boost::mutex::scoped_lock lock(mutex);
#endif #endif
std::map<std::string,WordVoc*>::iterator vi = vocs.find(filename); std::map<std::string,boost::shared_ptr<WordVoc> >::iterator vi = vocs.find(filename);
if (vi == vocs.end()) { if (vi == vocs.end()) {
WordVoc* voc = new WordVoc(); boost::shared_ptr<WordVoc> p(new WordVoc());
voc->Read(filename); // WordVoc* voc = new WordVoc();
vocs[filename] = voc; p.get()->Read(filename);
vocs[filename] = p;
} }
return vocs[filename]; return vocs[filename].get();
} }