United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6411042 : AWT Memory Leak

Details
Type:
Bug
Submit Date:
2006-04-10
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows_xp
Sub-Component:
java.awt
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0u6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

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
                                     
2006-12-12
EVALUATION

umbrella fix from 6407026
                                     
2006-10-02
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()
                                     
2006-05-10
EVALUATION

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



Hardware and Software, Engineered to Work Together