Greg Mattes
Greg Mattes

Reputation: 33979

Log4j Logger garbage collection?

Is there a way to force a Log4j Logger to be released/garbage collected?

In general, does Log4j "hang on" to Logger references in some static collection?

I see the Logger.shutdown() method, which is deprecated and refers to LoggerManager.shutdown(), which doesn't sound like it addresses a single Logger instance.

Upvotes: 0

Views: 1405

Answers (1)

Stephen C
Stephen C

Reputation: 719446

You could take a look at the log4j source code yourself.

Based on a quick trawl, I think the answers are:

Is there a way to force a Log4j Logger to be released/garbage collected?

Not with that level of granularity. The only thing I could find was a method (Heirarchy.clear()) that releases all loggers ... and destroy the logging hierarchy in the process.

In general, does Log4j "hang on" to Logger references in some static collection?

Yes. And the collection doesn't use weak references ...

Upvotes: 2

Related Questions