You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Leonid Kazantsev (JIRA)" <ji...@apache.org> on 2015/09/14 14:20:45 UTC

[jira] [Updated] (LOG4J2-1122) Memory leak with dymanic configuration.

     [ 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: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org