threadlocal回收
时间: 2023-09-12 14:04:02 浏览: 99
ThreadLocal的回收机制是这样的: 当ThreadLocal的key被垃圾回收器回收后,对应的value还在ThreadLocalMap中,这就造成了内存泄漏。因为key为null时,无法访问存储的副本数据。所以在使用完ThreadLocal之后,应该调用remove方法来释放内存。这样在JVM进行垃圾回收时,被弱引用关联的对象就会被回收掉。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [JVM之ThreadLocal及垃圾回收](https://blog.csdn.net/m0_52963553/article/details/126112176)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [关于ThreadLocal的学习心得及相关补充(垃圾回收机制等)](https://blog.csdn.net/m0_51736872/article/details/123075317)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文