JDK-7143857 : Memory leak in javax.swing.plaf.synth.SynthTreeUI
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u4
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2012-02-08
  • Updated: 2012-06-06
  • Resolved: 2012-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 7 JDK 8
7u4 b13Fixed 8Fixed
Description
J2SE Version (please include all output from java -version flag):
 JDK 6 and 7


Does this problem occur on J2SE 1.5 or 6ux?  Yes / No (pick one)
 N/A


Bug Description:

had experiencing memory problems with our swing base client app. 
Digging into the problem and found the root cause in 
"javax.swing.plaf.synth.SynthTreeUI". 

Checked the preview releases of jdk6 and 7 which both still 
contain the issue. Hope to adress this problem so that a fix 
would be encorporated in one of the next official release?

If it helps here is a short explaination of the problem and a possible fix:

1) Class "javax.swing.plaf.synth.SynthTreeUI" has a field named 
   "paintContext" of type "javax.swing.plaf.synth.SynthContext"

2) The field is set in the first line  of method 
   "protected void paint(SynthContext context, Graphics g)"

3) The field is never cleared

4) According to our memory analyzer tool the instance keeps 
   references to dialog instances, event if this dialog instances 
   have been disposed and are otherwise not reachable

5) According "javax.swing.plaf.synth.SynthContext" instances 
   should not be cached (from java doc: "A SynthContext should 
   only be considered valid for the duration of the method it is 
   passed to. In other words you should not cache a SynthContext 
   that is passed to you and expect it to remain valid.")


Fix: Null the reference at the end of the 
     "paint(SynthContext context, Graphics g)" 
     (there is alread a comment about "gc"):

        // Empty out the renderer pane, allowing renderers to be gc'ed.
        rendererPane.removeAll();
        paintContext = null; // <---------------- add this line

Comments
EVALUATION See main CR evaluation
16-02-2012