szetszwo commented on PR #6234: URL: https://github.com/apache/ozone/pull/6234#issuecomment-1967237111
> Instance object is having thread local object, which can have memory leak as thread local is not explicitly released. ... @sumitagrawl , `ThreadLocal` variables, like non-thread-local variables, are garbage collected. We don't have to release resources explicitly. Below is quoted from https://docs.oracle.com/javase/8/docs/api/java/lang/ThreadLocal.html > Each thread holds an implicit reference to its copy of a thread-local variable as long as the thread is alive and the ThreadLocal instance is accessible; after a thread goes away, all of its copies of thread-local instances are subject to garbage collection (unless other references to these copies exist). It may not be clear whether "after a thread goes away" is a required condition. Checked the `ThreadLocal` code, it has a `ThreadLocalMap` whose `Entry` extends `WeakReference<ThreadLocal<?>>`. Therefore, if there are no external references, a `ThreadLocal` variable is weakly reachable and will be garbage collected. Again, no recources need to be explicitly released. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
