Close leaked data

This commit is contained in:
Andrea Cavalli 2021-09-08 23:41:18 +02:00
parent 3a79e5ba6f
commit 5293fbe22c

View File

@ -83,14 +83,24 @@ public class CachedIndexSearcher {
@SuppressWarnings("deprecation")
@Override
protected void finalize() throws Throwable {
boolean failedToRelease = false;
if (usages > 0) {
failedToRelease = true;
logger.error("A cached index searcher has been garbage collected, but "
+ usages + " usages have not been released");
}
if (inCache) {
failedToRelease = true;
logger.error("A cached index searcher has been garbage collected, but it's marked"
+ " as still actively cached");
}
if (failedToRelease) {
try {
this.close();
} catch (Throwable ex) {
logger.warn("Error when closing cached index searcher", ex);
}
}
super.finalize();
}
}