3

I have been experiencing a PermGen memory issue and using Java VisualVM to debug it.

I traced the problem to a single line of code which is causing memory use to increase and never decrease. With this line of code no classes are getting unloaded.

The line of code is :

LogManager.getLogger(Logger.class.getName());

I am using log4j2. Does anyone have any suggestions to a fix to this line to be able to get rid of the memory problem?

2
  • Look here: stackoverflow.com/a/320469/4296831
    – Gren
    Jan 29, 2015 at 15:13
  • Can you add more detail? Is this a webapp, j2ee, or standalone? What log4j2 functions are you using? (All loggers async, mixed sync/async,...) if webapp, where are the log4j2 jars & config file? (In container lib or in webinf/lib?) Jan 30, 2015 at 0:08

1 Answer 1

0

This is an educated guess. As suggested by the link offered @Joachim in the comments, increasing PermGen space implies either an increasing number of classes loaded by the ClassLoader, or an increasing number of interned Strings.

(See this StackOverflow question to learn more about String interning)

Based on this, I would change your code to reference something static, which perhaps getName() does not give you.

I recommend either:

LogManager.getLogger(Logger.class.getName().intern());

Or as is more usually seen:

LogManager.getLogger(Logger.class);

But are you actually meaning to log against Logger.class?

Perhaps consider actually doing:

LogManager.getLogger(MyClassWhereLoggingHappens.class);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.