Repository navigation
Dispose JVM return values from function callbacks - #1040
Merged
masesdevelopers merged 3 commits intoMay 8, 2026
Merged
masesdevelopers merged 3 commits into
masesdevelopers merged 3 commits into
Conversation
Add optional disposal callbacks to Java.Util.Function delegates and ensure temporary JVM objects are disposed in JavaUtilExtensions. - Introduces OnApplyDispose / OnGetDispose properties (System.Action<T>) to BiFunction, BinaryOperator, DoubleFunction, Function, IntFunction, LongFunction, Supplier, and UnaryOperator. These are invoked after SetReturnValue to allow immediate disposal of JVM-backed return objects (defaults to null, invoked via null-conditional). - Updates MASES.JNet.Specific.Extensions.JavaUtilExtensions to dispose intermediate JVM objects created during collection/map conversions: uses try/finally to Dispose temporary jvmData, keys and values, and adds using for keySet where appropriate to avoid leaking JVM global references. This prevents leaking JVM global references by releasing them immediately when CLR-side code no longer needs the returned JVM objects.
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
| tInstance.Add(func != null ? func(item) : TJVMTypeInner.ToJVM(item)); | ||
| var jvmData = func != null ? func(item) : TJVMTypeInner.ToJVM(item); | ||
| #endif | ||
| using (var disposable = jvmData as IDisposable) |
| tInstance.Put(keyConverter(item.Key), valueConverter(item.Value)); | ||
| var key = keyConverter(item.Key); | ||
| var value = valueConverter(item.Value); | ||
| using (var keyDisposable = key as IDisposable) |
| var key = keyConverter(item.Key); | ||
| var value = valueConverter(item.Value); | ||
| using (var keyDisposable = key as IDisposable) | ||
| using (var valueDisposable = value as IDisposable) |
masesdevelopers
deleted the
1039-all-developed-javautilfunction-classes-does-not-contains-the-dispose-delegate
branch
May 8, 2026 08:51
This was referenced May 8, 2026
This was referenced Jun 15, 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.
Description
Add optional disposal callbacks to Java.Util.Function delegates and ensure temporary JVM objects are disposed in JavaUtilExtensions.
This prevents leaking JVM global references by releasing them immediately when CLR-side code no longer needs the returned JVM objects.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: