JDK-6411042 : AWT Memory Leak
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 5.0u6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-04-10
  • Updated: 2011-03-07
  • 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 7
7 b03Fixed
Related Reports
Relates :  
Description
Problem: Leak of java.awt.Panel when components created from SWT event thread

Environment: Windows XP (SP2)
              JDK 1.5.0_06 (also seen with 1.4.2_09)
              SWT 3.1.2

Unzip the attached application (ZQJleak.zip file), and run the following command from its main directory:

java -Djava.library.path=org.eclipse.swt -classpath TableExample;org.eclipse.swt\swt.jar SimpleTableDemo

After about 15-20 iterations it will throw an OutOfMemoryError.

Profiling with JProbe indicates that the Panel object is getting pinned by a JNI global reference.

I've only been able to reproduce this problem when the components are created in an SWT event thread, but note that the AWT/Swing components themselves are not embedded in SWT. The same code does not leak if the components are created from any other thread.

Also, the leak will go away if the JTable.setDropTarget() is called with a null argument right after the table is created.

Comments
SUGGESTED FIX umbrella fix from 6407026 webrev: http://sa.sfbay.sun.com/projects/awt_data/dolphin/6407026.3
12-12-2006

EVALUATION umbrella fix from 6407026
02-10-2006

EVALUATION Replacing SyncCall() with InvokeFunction() resolve the problem. Need to think if this is enough, or we should call InvokeFunction() from SyncCall().
10-05-2006

EVALUATION in fact the problematic code is registering DropTarget on JTable. So to remove all Swing code we need to create DropTarget for panel instead of creating JTable. It is an instance of AwtDropTarget who has a reference to the panel. This instance it not released because m_refs (reference counter) is not 0. For some reason OLE calls AddRef() more time than Release(). I suspect that this is bacause SWT calls OleInitialize() on its thread, which assumes that we use single-threaded apartment. We also call this function on Toolkit thread. And we use AwtDropTarget from both threads and this is vilation of single-threaded apartment. Perhaps we should use InvokeFunction() instead of SyncCall() for Java_sun_awt_windows_WComponentPeer_addNativeDropTarget() and Java_sun_awt_windows_WComponentPeer_removeNativeDropTarget()
10-05-2006