Skip to content

Commit

Permalink
[automation] Avoid memory leak on script loading failure (#4162)
Browse files Browse the repository at this point in the history
Core part of the fix for openhab/openhab-addons#16462.

Signed-off-by: Florian Hotze <[email protected]>
  • Loading branch information
florian-h05 authored Mar 27, 2024
1 parent e871dcf commit be9cbf2
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ public boolean loadScript(String engineIdentifier, InputStreamReader scriptData)
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;
Expand Down

0 comments on commit be9cbf2

Please sign in to comment.