[go: nahoru, domu]

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

Use Threadlocal.remove() instead of .set(null) in documentation #32874

Closed

Conversation

Seungpang
Copy link
Contributor

Hi Team,

This PR updates the Spring Framework documentation to recommend using ThreadLocal.remove() instead of ThreadLocal.set(null) when unsetting a ThreadLocal value.

The current documentation suggests using ThreadLocal.set(null) to unset a ThreadLocal value. However, this approach can lead to memory leaks and other unexpected behaviors, particularly in multi-threaded and multi-classloader environments. Using ThreadLocal.set(null) does not completely remove the ThreadLocal instance, which means the associated memory may not be fully released. This can cause data inconsistencies and unexpected behaviors.

In the Spring Framework itself, ThreadLocal.remove() is used to ensure that the ThreadLocal values are properly cleaned up, preventing potential memory leaks and ensuring consistent behavior across different environments.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 22, 2024
@jhoeller jhoeller added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels May 22, 2024
@jhoeller jhoeller added this to the 6.1.9 milestone May 22, 2024
@snicoll snicoll self-assigned this May 23, 2024
snicoll added a commit that referenced this pull request May 23, 2024
@snicoll snicoll closed this in 31f298b May 23, 2024
@snicoll
Copy link
Member
snicoll commented May 23, 2024

Good catch, thanks @Seungpang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants