JDK-6758673 : WeakReference leak in Window.ownedWindowList
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-10-13
  • Updated: 2013-06-22
  • Resolved: 2011-03-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u60Fixed 7 b48Fixed
Description
There is a leak in the list of owned child windows for every window. Run the attached test and check output: test prints two counters, one for weak reference with null value, and another is for not-null value. It's clear that target objects (child windows) are properly destroyed, however the corresponding weak refereces are never removed from ownedWindowList.

Comments
EVALUATION The problem is easily understandable. Indeed, when a window disposer record is created: WindowDisposerRecord(AppContext context, Window victim) { owner = new WeakReference<Window>(victim.getOwner()); weakThis = victim.weakThis; this.context = new WeakReference<AppContext>(context); } victim's owner is still null, because WindowDisposerRecord is called from init(), while owner is instantiated in ownedInit(). That's why I suggest moving window disposer record creation into the end of ownedInit() - see suggested fix for details.
13-10-2008

SUGGESTED FIX --- a/src/share/classes/java/awt/Window.java Mon Sep 29 20:16:42 2008 +0200 +++ b/src/share/classes/java/awt/Window.java Mon Oct 13 13:26:49 2008 +0400 @@ -53,6 +53,7 @@ import sun.awt.CausedFocusEvent; import sun.awt.CausedFocusEvent; import sun.awt.SunToolkit; import sun.awt.util.IdentityArrayList; +import sun.java2d.Disposer; import sun.java2d.pipe.Region; import sun.security.action.GetPropertyAction; import sun.security.util.SecurityConstants; @@ -409,8 +410,6 @@ public class Window extends Container im } modalExclusionType = Dialog.ModalExclusionType.NO_EXCLUDE; - - sun.java2d.Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this)); } /** @@ -540,6 +539,8 @@ public class Window extends Container im if (owner != null) { owner.addOwnedWindow(weakThis); } + + Disposer.addRecord(anchor, new WindowDisposerRecord(appContext, this)); } /**
13-10-2008