[logback-dev] [JIRA] Commented: (LBCLASSIC-172) Use WeakHashMap instead of Hashtable in LoggerContext
Joern Huxhorn (JIRA)
noreply-jira at qos.ch
Tue Dec 15 08:17:33 CET 2009
[ http://jira.qos.ch/browse/LBCLASSIC-172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=11457#action_11457 ]
Joern Huxhorn commented on LBCLASSIC-172:
-----------------------------------------
A logger kept in a static field of a class would only get garbage-collected if said class (not it's instances) is garbage-collected, i.e. if the classloader that initially loaded that class is garbage-collected.
A normal classloader keeps a hard reference to every loaded class. Some webapp classloader might handle this different to provide the ability to unload a webapp.
WeakHashMap essentially works like a cache. References are only removed during garbage-collection, i.e. if memory is low anyway, and only if no hard reference preventing garbage-collection is left at that time.
I guess that, in practice, there wouldn't be much difference and loggers wouldn't be recreated that often. We could check that by implementing a WeakHashMap ourselves which prints something when a reference is collected using a ReferenceQueue.
The trick would be to keep hard references of any configured logger in LoggerContext. Upon reconfiguration those could be handled as necessary.
> Use WeakHashMap instead of Hashtable in LoggerContext
> -----------------------------------------------------
>
> Key: LBCLASSIC-172
> URL: http://jira.qos.ch/browse/LBCLASSIC-172
> Project: logback-classic
> Issue Type: Bug
> Components: Other
> Affects Versions: 0.9.18
> Reporter: Joern Huxhorn
> Assignee: Logback dev list
> Fix For: unspecified
>
>
> Preventing garbage-collection of unused Loggers is a bad idea.
> The following code should not fail:
> for(int i=0;i<10000000;i++) {
> LoggerFactory.getLogger("Foo."+i).debug("Foo!");
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.qos.ch/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the logback-dev
mailing list