logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Memory leak by not disposing loggers
Date Mon, 20 Apr 2015 03:58:44 GMT
On Sun, Apr 19, 2015 at 6:21 PM, Ralph Goers <ralph.goers@dslextreme.com>
wrote:

> Creating a Logger is a relatively expensive operation (especially when
> using the ClassLoaderContextSelector).  Furthermore, many users call
> getLogger(class name) for every instance of their class. As such, keeping
> them cached makes sense. Although I haven’t looked at what
> java.util.logging does, every other framework I have looked at keeps them
> permanently cached.
>
> In log4j 1 (and Logback last I checked) a reconfiguration would run
> through every logger object and remove all of its configuration. The Logger
> objects themselves aren’t freed during a configuration. Similarly, Log4j 2
> does not remove Loggers during a reconfiguration. New LoggerConfig objects
> will be created and the Loggers will be pointed at the new LoggerConfigs.
> The old LoggerConfig objects will be freed, along with old Appenders and
> Filters.
>

FYI: I added the last few sentences to the Javadoc in
org.apache.logging.log4j.core.LoggerContext.reconfigure().

Gary

>
> Ralph
>
>
> > On Apr 19, 2015, at 4:44 PM, Gary Gregory <garydgregory@gmail.com>
> wrote:
> >
> > Hm, ok, but that does not deal with this user's issue directly. Let's see
> > what he comes back with...
> >
> > Gary
> >
> > On Sun, Apr 19, 2015 at 4:36 PM, Remko Popma <remko.popma@gmail.com>
> wrote:
> >
> >> No, I think the old LoggerConfig objects can be GC-ed after a
> >> reconfiguration.
> >>
> >> Sent from my iPhone
> >>
> >>> On 2015/04/20, at 8:07, Gary Gregory <garydgregory@gmail.com> wrote:
> >>>
> >>> Are loggers GC'd on a reconfigure?
> >>> Gary
> >>>
> >>> -------- Original message --------
> >>> From: Remko Popma <remko.popma@gmail.com>
> >>> Date: 04/19/2015  15:33  (GMT-08:00)
> >>> To: Log4J Users List <log4j-user@logging.apache.org>
> >>> Subject: Re: Memory leak by not disposing loggers
> >>>
> >>> Loggers are not GC-ed until the whole logging subsystem is GC-ed. That
> >> is until your webapp is unloaded or standalone process is stopped.
> >>> Is your app a webapp?
> >>>
> >>> Sent from my iPhone
> >>>
> >>>> On 2015/04/20, at 1:27, Gary Gregory <garydgregory@gmail.com>
wrote:
> >>>>
> >>>> The LoggerContext.loggers is a ConcurrentHashMap<String, Loggers>.
It
> >>>> sounds like you need the effect of a ConcurrentHashMap with weak
> >> values...
> >>>>
> >>>> Gary
> >>>>
> >>>> On Sun, Apr 19, 2015 at 2:27 AM, Veselin M
> >> <veselin_m84@yahoo.com.invalid>
> >>>> wrote:
> >>>>
> >>>>> Hello all,
> >>>>>
> >>>>> I have a memory leak problem with Log4j2. I’m using SLF4J to get
> >> loggers
> >>>>> for my objects. Unfortunately when they get garbage collected the
> >> logger
> >>>>> remains cached in LoggerContext.loggers in the log4j framework.
Is
> >> there
> >>>>> any way to prevent the caching or to remove the logger?
> >>>>>
> >>>>> Regards
> >>>>> Veselin
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>>>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>>
> >>>>
> >>>> --
> >>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>>> Java Persistence with Hibernate, Second Edition
> >>>> <http://www.manning.com/bauer3/>
> >>>> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> >>>> Spring Batch in Action <http://www.manning.com/templier/>
> >>>> Blog: http://garygregory.wordpress.com
> >>>> Home: http://garygregory.com/
> >>>> Tweet! http://twitter.com/GaryGregory
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >>> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> >> For additional commands, e-mail: log4j-user-help@logging.apache.org
> >>
> >>
> >
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message