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?

Stewart
  • 17,616
  • 8
  • 52
  • 80
Alex Thomson
  • 143
  • 1
  • 3
  • 10
  • Look here: http://stackoverflow.com/a/320469/4296831 – Gren Jan 29 '15 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?) – Remko Popma Jan 30 '15 at 00:08

1 Answers1

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);
Stewart
  • 17,616
  • 8
  • 52
  • 80