Skip to content

Commit

Permalink
dict/dict: Fix memory leaks at program termination
Browse files Browse the repository at this point in the history
Avoid dynamic memory allocation for the static variable 'cache'.
Now the destructor for that variable is called automatically
when Tesseract terminates and releases all associated memory.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 25, 2016
1 parent 55bcfb5 commit 6fad5fc
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions dict/dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,10 @@ Dict::~Dict() {
}

DawgCache *Dict::GlobalDawgCache() {
// We dynamically allocate this global cache (a singleton) so it will outlive
// every Tesseract instance (even those that someone else might declare as
// global statics).
static DawgCache *cache = new DawgCache(); // evil global singleton
return cache;
// This global cache (a singleton) will outlive every Tesseract instance
// (even those that someone else might declare as global statics).
static DawgCache cache;
return &cache;
}

void Dict::Load(DawgCache *dawg_cache) {
Expand Down

0 comments on commit 6fad5fc

Please sign in to comment.