Merged
Conversation
The runtime is cleared to remove another reference and assist GC. The termination flag is added to ensure a terminated LocalContext is not used for any further changes.
The function here previously was an instance method, rooting a reference to the ClassValue via JavaSupport. This caused the proxy class contained in the ClassValue to be permanently hard- referenced, preventing the JRuby runtime from being collected. The new function is static and accepts the runtime and lock previously accessed via the JavaSupport reference. Once the JavaSupport has been removed from the runtime on tearDown, the chain of references to this class value is broken and all objects downstream of JavaSupport are unrooted.
LoadService.tearDown calls RubyArray.clear on the loaded features, which uses the current thread context for error handling. Errors here should be exceedingly rare, but if they are raised the will need a proper ThreadContext to construct and propagate properly.
Locking against the StableClassValue causes the StableValue to have a hard reference back to the ClassValue that contains it, preventing the ClassValue from ever vacating. This leaks memory no matter what the StableValue contains.
We can actively clear ThreadContext references and remove the ThreadLocal association for the tearDown thread.
Continue isolating the ClassValue calculators from JavaSupport. * Use weak references to avoid rooting state needed by the calculators. * Use static factory methods to ensure no attachment to the surrounding JavaSupport object. * Add a clear method to our ClassValue for best-effort clearing. * StableClassValue tracks StableValue instances to actively clear them at tearDown. * Clear as many references as possible.
Contributor
|
Thanks for the fix, @headius! My openhab test setup is no longer leaking with this. |
This test runs some very basic verifications of the GCability of the Ruby runtime associated with a ScriptingContainer once it has been terminated. See jruby#520
This was referenced Apr 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will reconsider and apply appropriate fixes from #9315.
The fixes and analysis in that PR were performed by Copilot, and after several of them turned out to be unnecessary or incorrect, we lost faith that any of the fixes were correct or based on sound analysis. This PR will attempt to re-visit that analysis and apply only necessary, correct fixes.