Alex Rivera | Logout

Threadlocal remove?

Asked 2012-09-14T12:44:32.343
23

When using a ThreadLocal should I always call remove() when I am done or when I do set the old value is replaced anyway so remove is redundant?

Edit
Report

1 Answer

1

I will make it simple: If you extend the ThreadLocal for any reason use remove(). On vanilla ThreadLocal use set(null). Basically not using ThreadLocal.remove() on an extended ThreadLocal can lead to memory leaks (ClassLoader ones most likely)

If you need more details why, post a comment.

answered 2012-09-14T13:16:39.393

Your Answer