(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,13 +60,16 @@ public class SentenceExtractor {
}
synchronized (this) {
ngramLexicon = new NgramLexicon(models);
try {
rdrposTagger = new RDRPOSTagger(models.posDict, models.posRules);
if (ngramLexicon == null) {
ngramLexicon = new NgramLexicon(models);
}
catch (Exception ex) {
throw new IllegalStateException(ex);
if (rdrposTagger == null) {
try {
rdrposTagger = new RDRPOSTagger(models.posDict, models.posRules);
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
}