Skip to content
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

WELD-2750 Tweak how parent-child creational contexts are created. Use WeakReference to keep track of destroyed instance. #2871

Merged
merged 2 commits into from Aug 8, 2023

Conversation

manovotn
Copy link
Contributor

@manovotn manovotn commented Aug 4, 2023

Attempts to solve a memory leak in dependent instance handling.
See the JIRA (WELD-2750) for detailed description and a reproducer.

First commit:

  • Makes sure the set of destroyed instance we keep in each CC is a WeakReference allowing GC to collect them.
  • Also changes how we create CC for non-dependent beans when obtaining injectable reference - we no longer unconditionally create child CC as that implies linked them together and potentially holding a reference to an already destroyed instance.

Second commit:

  • An improvement on the second step of first commit - tries to avoid creating any superfluous CC when not needed. A side effect is that BeanManagerImpl#getReference can no longer return null.
    • However, after browsing code I didn't see any such usage anyway - CI might still prove me wrong though as I only ran non-container tests locally :)

@manovotn
Copy link
Contributor Author

manovotn commented Aug 4, 2023

CC @ljnelson as this affects the code you recently contributed.

@ljnelson
Copy link
Contributor

ljnelson commented Aug 4, 2023

Haven't looked in detail but WeakReference was absolutely where I wanted to go initially but didn't think it was worth the complexity. Clearly I was wrong!

@manovotn manovotn merged commit d80027f into weld:master Aug 8, 2023
12 checks passed
@manovotn manovotn deleted the weld2750 branch August 8, 2023 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants