United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6543126 : Level.known can leak memory

Details
Type:
Bug
Submit Date:
2007-04-05
Status:
Open
Updated Date:
2014-12-15
Project Name:
JDK
Resolved Date:
Component:
core-libs
OS:
linux
Sub-Component:
java.util.logging
CPU:
x86
Priority:
P3
Resolution:
Unresolved
Affected Versions:
7
Targeted Versions:
9

Related Reports
Duplicate:
Relates:

Sub Tasks

Description
See

http://blogs.sun.com/fkieviet/entry/classloader_leaks_the_dreaded_java

for a description of the problem.

                                    

Comments
I agree with Jesse that the Level API usage pattern isn't well designed for subclassing.  To lookup a known level instance, the name and value of the custom level instance are adequate.  A factory method to create custom Level instances is one good solution; or another option is to cache a Level instance of the custom name/value instead of the subclass instance.

Another observation to the Level API is that Level constructors initializes 3 final fields (name, value, resourceBundleName).  However, Level.getName(), Level.getLocalizedName() and getResouorceBundleName() are not final and can be overridden. It's not obvious why not all Level instance methods are final and possibly an oversight.  Unless there is a good reason to keep a reference to the Level subclass (I can't think of any), we should consider deprecating the Level class and define a new subclass to fix the memory leak and also address custom levels requirements/issues together.
                                     
2012-12-12
As java.util.logger belongs to corelib now, put it back to the pool.
                                     
2012-10-16
EVALUATION

This is important bug which has to be fixed at least in the current release.
Changing the implementation to use WeakReference's is relatively easy but
most likely the fix would require a spec change, so a CCC request is going to be needed.

Many thanks to Frank for describing the problem and to Jesse for filing this CR!
                                     
2007-04-18
SUGGESTED FIX

Level.unknown should be a List<Reference<Level>> storing WeakReference's.

Perhaps there should also be some factory method to create Level instances with particular labels and numeric values; subclassing an enumeration-like class such as Level is a highly suspect API usage pattern which should probably be deprecated.
                                     
2007-04-05



Hardware and Software, Engineered to Work Together