[ 
https://issues.apache.org/jira/browse/LOG4J2-1122?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Leonid Kazantsev updated LOG4J2-1122:
-------------------------------------
    Description: 
There are put to 
{code}private final ConcurrentMap<String, Logger> loggers = new 
ConcurrentHashMap<String, Logger>();
at LoggerContext
{code}

But there is no remove, that's cause memory leak when using dynamic 
configuration. Removing logger from configuration is not removing that logger 
from context. 
Also there is no right way to remove it from context.
I'm using simple workaround for that issue:

{code}
loggersField = LoggerContext.class.getDeclaredField("loggers");
loggersField.setAccessible(true);
ConcurrentMap<String, org.apache.logging.log4j.core.Logger> loggers = 
(ConcurrentMap<String, org.apache.logging.log4j.core.Logger>) 
loggersField.get(ctx);
loggers.remove(loggerName);
{code}

  was:
There are put to 
{code}private final ConcurrentMap<String, Logger> loggers = new 
ConcurrentHashMap<String, Logger>();
at LoggerContext
{code}

But there is no remove, that's cause memory leak when using dynamic 
configuration. Removing logger from configuration is not removing that logger 
from context. 
I'm using simple workaround for that issue:

{code}
loggersField = LoggerContext.class.getDeclaredField("loggers");
loggersField.setAccessible(true);
ConcurrentMap<String, org.apache.logging.log4j.core.Logger> loggers = 
(ConcurrentMap<String, org.apache.logging.log4j.core.Logger>) 
loggersField.get(ctx);
loggers.remove(loggerName);
{code}


> Memory leak with dymanic configuration.
> ---------------------------------------
>
>                 Key: LOG4J2-1122
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1122
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.2, 2.3
>            Reporter: Leonid Kazantsev
>
> There are put to 
> {code}private final ConcurrentMap<String, Logger> loggers = new 
> ConcurrentHashMap<String, Logger>();
> at LoggerContext
> {code}
> But there is no remove, that's cause memory leak when using dynamic 
> configuration. Removing logger from configuration is not removing that logger 
> from context. 
> Also there is no right way to remove it from context.
> I'm using simple workaround for that issue:
> {code}
> loggersField = LoggerContext.class.getDeclaredField("loggers");
> loggersField.setAccessible(true);
> ConcurrentMap<String, org.apache.logging.log4j.core.Logger> loggers = 
> (ConcurrentMap<String, org.apache.logging.log4j.core.Logger>) 
> loggersField.get(ctx);
> loggers.remove(loggerName);
> {code}



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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to