Does your app make a lot of large log messages or is it just used in a
couple loggers? Because I think you could use a custom MessageFactory for
those loggers to reduce memory usage at the cost of performance.

On 11 March 2016 at 14:08, luca boncompagni <[email protected]> wrote:

>
> Il 11/mar/2016 20:17, "Gary Gregory" <[email protected]> ha scritto:
> >
> > On Fri, Mar 11, 2016 at 8:38 AM, luca boncompagni <[email protected]>
> wrote:
> >>
> >> Hi to all,
> >>
> >> I'm using lo4j2-2.5 and I have some memory usage problems with
> >> AbstractStringLayout.getStringBuilder(). If I write a very long line
> >> of log, the memory used by this line of log is never cleaned.
> >>
> >> In the code, I see result.setLength(0) that sets the current size to
> >> 0, but the buffer of the string builder remains as long as it is.
> >>
> >> Should be ok to use something like this:
> >>
> >> result.setLength(0);
> >> result.setLength(DEFAULT_STRING_BUILDER_SIZE);
> >> result.trimToSize();
> >>
> >> I have another question, why we should use a threadlocal to get an
> >> empty StringBuilder?
> >
> >
> > Performance. It saves a lot of time and memory to avoid creating a new
> StringBuilder for each log event.
> >
> > Gary
>
> Ok, I'll do some test.
>
> Can you help me about memory usage?
>
> Luca
>



-- 
Matt Sicker <[email protected]>

Reply via email to