[ 
https://issues.apache.org/jira/browse/LOG4J2-1142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14939739#comment-14939739
 ] 

Remko Popma commented on LOG4J2-1142:
-------------------------------------

I will look at the ObjectPool performance and report results here.

For the record, I think this is not a real problem, but we are just being 
afraid of our own shadow here. A memory leak cannot happen in our case. [This 
article|https://neilmadden.wordpress.com/2014/07/21/threadlocal-variables-and-permgen-memory-leaks-not-always-a-leak/]
 clarified things for me: it's about the value. 
[Succinctly|http://blog.crazybob.org/2006/02/threadlocal-memory-leak.html]:

{quote}
ThreadLocal is implemented as a weak hash map. Each thread has a map instance. 
The map keys are weak references to the ThreadLocal instances themselves. The 
map values are the thread local values. Just like with WeakHashMap instances, 
if your value somehow holds a strong reference to the ThreadLocal key, the 
garbage collector can't reclaim either until you explicitly set the value to 
null or even better call remove() on the ThreadLocal instance.
{quote}

Our value is a StringBuilder and not a Log4j class, so a memory leak cannot 
occur. Still, there is a _lot_ of confusion about this topic and Tomcat 
complains loudly which will worry our users and cause us to spend time 
investigating. Silencing the unnecessary Tomcat warnings is my main motivation 
for addressing this issue.

> ThreadLocals in Layout implementations should be non-static to prevent memory 
> leaks in web containers
> -----------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1142
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1142
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Layouts
>    Affects Versions: 2.4
>            Reporter: Dmitri Blinov
>            Assignee: Remko Popma
>             Fix For: 2.4.1
>
>         Attachments: LOG4J2-1142.patch
>
>
> As discussed in LOG4J2-1125, storing ThreadLocal<StringBuilder> in a static 
> field may not interact well with the thread pools and class loaders of some 
> web containers and may result in memory leaks, especially in older web 
> containers.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to