(sentence-extractor) Fix resource leak in sentence extractor

The code would always re-initialize the static ngramLexicon and rdrposTagger fields with new instances even if they were already instantiated, leading to a ton of unnecessary RAM allocation.

The modified behavior checks for nullity before creating a new instance.
This commit is contained in:
Viktor Lofgren 2024-04-05 18:52:58 +02:00
parent e3316a3672
commit adc90c8f1e

View File

@ -60,15 +60,18 @@ public class SentenceExtractor {
} }
synchronized (this) { synchronized (this) {
if (ngramLexicon == null) {
ngramLexicon = new NgramLexicon(models); ngramLexicon = new NgramLexicon(models);
}
if (rdrposTagger == null) {
try { try {
rdrposTagger = new RDRPOSTagger(models.posDict, models.posRules); rdrposTagger = new RDRPOSTagger(models.posDict, models.posRules);
} } catch (Exception ex) {
catch (Exception ex) {
throw new IllegalStateException(ex); throw new IllegalStateException(ex);
} }
} }
}
} }