I just happened to take a glance at this and noticed the remove method on the KnownLevels doesn't quite look right. Using Optional.of(nameToLevels.get(mirroredLevel.name)).ifPresent((x) -> x.remove(this)); will produce an NPE if the level is not present. If the intention is that the levels may not be present in the list the Optional.ofNullable() should be used.
On Mon, Jul 25, 2016 at 11:10 AM, Daniel Fuchs <daniel.fu...@oracle.com> wrote: > Hi, > > Please find below a fix for: > > 6543126: Level.known can leak memory > https://bugs.openjdk.java.net/browse/JDK-6543126 > > webrev: > http://cr.openjdk.java.net/~dfuchs/webrev_6543126/webrev.00 > > This is a fix for a long standing issue: Level maintains a list > of know levels which has strong references to any created levels. > Because the references are strong references, they prevent the garbage > collection of levels, level classes, and level class loaders. > > This fix changes the KnownLevel class to extend WeakReference<Level> > in order to only retain a weak reference to custom level instances. > > best regards, > > -- daniel > -- James R. Perkins JBoss by Red Hat