[automation] Avoid memory leak on script loading failure (#4162)

Core part of the fix for https://github.com/openhab/openhab-addons/issues/16462.

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
This commit is contained in:
Florian Hotze 2024-03-27 22:32:20 +01:00 committed by GitHub
parent e871dcfa47
commit be9cbf2649
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -175,7 +175,13 @@ public class ScriptEngineManagerImpl implements ScriptEngineManager {
return true;
} catch (Exception ex) {
logger.error("Error during evaluation of script '{}': {}", engineIdentifier, ex.getMessage());
logger.debug("", ex);
// Only call logger if debug level is actually enabled, because OPS4J Pax Logging holds (at least for
// some time) a reference to the exception and its cause, which may hold a reference to the script
// engine.
// This prevents garbage collection (at least for some time) to remove the script engine from heap.
if (logger.isDebugEnabled()) {
logger.debug("", ex);
}
}
}
return false;