Skip to content

Adjust operators to dereference resources after cleanup, enabling them for garbage collection #4035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

georgebanasios
Copy link
Contributor

@georgebanasios georgebanasios commented Jun 13, 2025

Fixes: #3199

This change addresses a memory leak in the Mono#using, Flux#using, and Flux#usingWhen operators. Currently, their internal subscribers retain a strong reference to the managed resource even after the resourceCleanup action has been executed. This prevents the resource from being garbage collected, leading to potential memory issues.

Also, the issue mentions an example of Flux#fromIterable, which is in combination with Flux#using.
The Flux#using operator is designed for "one-time" use of a resource per subscriber correct?
The Flux#fromIterable is resubscribable which removing the reference to the iterable, changes the design of the operator.

Let me know your thoughts on this approach. I'm happy to make any changes needed.

…m for garbage collection

Signed-off-by: George Banasios <[email protected]>
@georgebanasios georgebanasios requested a review from a team as a code owner June 13, 2025 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reactor core primitives Flux#using, Flux#usingWhen, Flux#fromIterable should be GC friendly to prevent memory leak
1 participant