[slf4j-dev] [Bug 266] New: Memory Leak: Clearing MDC context with Log4J
bugzilla-daemon at qos.ch
bugzilla-daemon at qos.ch
Mon Jul 16 09:29:44 CEST 2012
http://bugzilla.slf4j.org/show_bug.cgi?id=266
Summary: Memory Leak: Clearing MDC context with Log4J
Product: SLF4J
Version: 1.6.x
Platform: All
OS/Version: All
Status: NEW
Severity: major
Priority: P1
Component: Implementations
AssignedTo: slf4j-dev at qos.ch
ReportedBy: f.bantner at axon-e.de
Recently after a long time log4j got it's problem with clearing the MDC context
and the underlying ThreadLocal Hashmap fixed. S.
https://issues.apache.org/bugzilla/show_bug.cgi?id=50486
This fixed a long running Problem with Tomcat freeing memory on reload.
In order to do so, log4j's MDC got the clear method with 1.2.16 and with 1.2.17
fixed it so that it works.
Log4j has an MDC adaptor for Log4J and it's own clear method. But instead of
calling Log4J's clear it implements essentially (MDC.getContext()).clear()
which only clears the HashMap but doesn't remove it from the ThreadLocal
context resulting in a MemroryLeak.
Short workaround: Instead of calling slf4j's MDC.clear() call log4j's
MDC.clear() (but that is the exact opositit of what slf4j is made for)
Simple Fix: change log4j's mdc adaptor to call MDC.clear() instead of
MDC.getContext().clear().
More complex fix: If backward compatibility is an issue (like it was für log4j)
than log4js solution can be applied here: Instead of calling MDC.clear()
directly call it via reflexion if it exists and otherwise keep calling
MDC.getContext().clear().
--
Configure bugmail: http://bugzilla.slf4j.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
More information about the slf4j-dev
mailing list