[ https://issues.apache.org/jira/browse/LOG4J2-2201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16570817#comment-16570817 ]
ASF subversion and git services commented on LOG4J2-2201: --------------------------------------------------------- Commit 16e73c9f44e3a673cea61a7644f51362bd91dd31 in logging-log4j2's branch refs/heads/release-2.x from [~ckozak] [ https://git-wip-us.apache.org/repos/asf?p=logging-log4j2.git;h=16e73c9 ] [LOG4J2-2201] Fix memory leak in ReusableParameterizedMessage When emptyReplacement length is less than 10 but large enough for the current paramers, the ReusableParameterizedMessage would retain references to the most recently logged parameters. > ReusableParametrizedMessages keeps references to objects beyond their > expected lifetime > --------------------------------------------------------------------------------------- > > Key: LOG4J2-2201 > URL: https://issues.apache.org/jira/browse/LOG4J2-2201 > Project: Log4j 2 > Issue Type: Bug > Components: API > Affects Versions: 2.8.2 > Environment: Linux, ubuntu 14.04, java 8u151 > Reporter: mhstnsc > Assignee: Carter Kozak > Priority: Major > > During some memory leak analysis i noticed that one of my object which was > expected to die was kept alive for longer than expected. The only reference > to it was in ReusableParametrizedMessage > This object was pretty heavy and hold tens-hundreds of references to child > object alive also. > I had to disable logging to test the leaks. > The side effect to this is: > # Holding the references longer than expected will move the memory from > young generation to tenured generation where collection is more expensive and > affect performance > # Debugging memory leaks just became harder. > ReusableParametrizedMessage should not hold references to objects beyond > their intended lifetime > As you can see in this sample code > {code:java} > ReusableParameterizedMessage set(final String messagePattern, final Object > p0) { > params[0] = p0; > init(messagePattern, 1, params); > return this; > } > ReusableParameterizedMessage set(final String messagePattern, final Object > p0, final Object p1) { > params[0] = p0; > params[1] = p1; > init(messagePattern, 2, params); > return this; > }{code} > > If i call set(pattern,p0,p1) and then set(pattern, p0) ...then reference to > p1 is kept alive until overriden by another set. > I don't have an understanding about log4j inner workings but for me the > references should be kept only for the duration of the call to log. > I would be happy to be able to disable the mechanism. We are anyway running > the software with INFO level and without logging the data plane so this > optimization does not really bring much. > How about just setting the params to null after finishing the logging ? > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)