Ensure Thread can be collected in a timely manner if Recycler.Stack h…#7499
Closed
normanmaurer wants to merge 1 commit into4.1from
Closed
Ensure Thread can be collected in a timely manner if Recycler.Stack h…#7499normanmaurer wants to merge 1 commit into4.1from
normanmaurer wants to merge 1 commit into4.1from
Conversation
…olds a reference to it. Motivation: In our Recycler implementation we store a reference to the current Thread in the Stack that is stored in a FastThreadLocal. The Stack itself is referenced in the DefaultHandle itself. A problem can arise if a user stores a Reference to an Object that holds a reference to the DefaultHandle somewhere and either not remove the reference at all or remove it very late. In this case the Thread itself can not be collected as its still referenced in the Stack that is referenced by the DefaultHandle. Modifications: - Use a WeakReference to store the reference to the Thread in the Stack - Add a test case Result: Ensure a Thread can be collected in a timely manner in all cases even if it used the Recycler.
3d2e0dd to
2b2bf66
Compare
johnou
approved these changes
Dec 13, 2017
trustin
approved these changes
Dec 13, 2017
Member
Author
Scottmitch
reviewed
Dec 14, 2017
| thread = null; | ||
|
|
||
| // Loop until the Thread was collected. If we can not collect it the Test will fail due of a timeout. | ||
| while (!collected.get()) { |
Member
There was a problem hiding this comment.
This test is a bit speculative, and dependent upon VM/GC behavior. Hopefully all GCs behaves as expected and will reclaim/finalize the object in time. I'm not sure of a better way to test this, but this maybe subject to sporadic test failures (maybe unlikely though?).
Member
Author
There was a problem hiding this comment.
@Scottmitch I think its the best we can do... If there will be ever a better API I am happy to revisit it.
Member
There was a problem hiding this comment.
If it starts failing I guess we can take a closer look and consider disabling it if necessary.
Member
Author
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.
…olds a reference to it.
Motivation:
In our Recycler implementation we store a reference to the current Thread in the Stack that is stored in a FastThreadLocal. The Stack itself is referenced in the DefaultHandle itself. A problem can arise if a user stores a Reference to an Object that holds a reference to the DefaultHandle somewhere and either not remove the reference at all or remove it very late. In this case the Thread itself can not be collected as its still referenced in the Stack that is referenced by the DefaultHandle.
Modifications:
Result:
Ensure a Thread can be collected in a timely manner in all cases even if it used the Recycler.