JDK-4294016 : Another java.awt.dnd.DropTarget causing JNI Global Reference leak?
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.2_003,1.2.2_005
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_7,windows_nt
  • CPU: x86,sparc
  • Submitted: 1999-11-23
  • Updated: 2001-07-02
  • Resolved: 2000-03-08
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.
Other Other Other Other
1.2.2_005 005Fixed 1.3.0_02Fixed 1.3.1Fixed 1.4.0Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
I have a customer that is still seeing a JNI Global Reference to his 
unreferenced objects when using JDK1.2.2_003 that has the fix for bug 
4224888.  I have tested the sample code below with JDK1.2.2_003 
the memory leak still present.


TestCase:

import java.awt.*;
import java.awt.dnd.*;
import java.awt.dnd.peer.*;
import java.awt.event.*;
import java.awt.peer.*;
import javax.swing.*;

public class bugDropTargetLeak extends JFrame
{
  DropTarget _dt;

  public bugDropTargetLeak()
  {
    super("Test Window");

    _dt = new DropTarget(this, null);

    setSize(400, 400);
  }

  protected void processWindowEvent(WindowEvent we)
  {
    if (we.getID() == WindowEvent.WINDOW_CLOSING)
    {
      System.out.println("window closing...");
      if (_dt != null)
      {
        _dt.setComponent(null);

        // The following is to workaround the bug in removeDropTarget(), i.e.
        // we need to call it twice for it to invoke the native
        // removeNativeDropTarget().  getPeer() is a deprecated method, but
        // it's the only workaround I know of.
        ((DropTargetPeer)getPeer()).removeDropTarget(_dt);

        // Clear out the variable just so we have less clutter when analyzing
        // using HAT.
        _dt = null;
      }
      dispose();
    }

    super.processWindowEvent(we);
  }

  public static void main(String[] args)
  {
    JFrame    f  = new JFrame("Main Window");
    Container cp = f.getContentPane();
    JButton   b  = new JButton("Click me to launch a leaked window");

    f.getContentPane().add(b, "North");
    b.addActionListener(new ActionListener()
 {
      public void actionPerformed(ActionEvent ae)
      {
        (new bugDropTargetLeak()).setVisible(true);
      }
    });

    b = new JButton("gc()");
    f.getContentPane().add(b, "South");
    b.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent ae)
      {
        System.out.print("Calling system.gc() and System.runFinalization(): ");
        System.gc();
        System.out.print(".");
        System.gc();
        System.out.print(".");
        System.runFinalization();
        System.out.print(".");
        System.gc();
        System.out.print(".");
        System.gc();
        System.out.print(".");
        System.runFinalization();
        System.out.print(".");
        System.gc();
        System.out.print(".");
        System.gc();
        System.out.println("  done");
      }
    });

    f.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent we)
      {
        System.exit(0);
      }
    });

    f.pack();
    f.setVisible(true);
  }
}


Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2.2_005 ladybird merlin-beta INTEGRATED IN: 1.2.2_005 1.3.0_02 1.3.1 ladybird merlin-beta VERIFIED IN: 1.2.2_005 1.3.0_02
14-06-2004

SUGGESTED FIX ------- WComponentPeer.java ------- *** /tmp/d0mD4Zg Mon Jan 3 10:48:54 2000 --- WComponentPeer.java Mon Nov 29 11:56:26 1999 *************** *** 386,392 **** */ public synchronized void removeDropTarget(DropTarget dt) { ! if (nDropTargets-- == 0) { removeNativeDropTarget(); nativeDropTargetContext = 0; } --- 386,392 ---- */ public synchronized void removeDropTarget(DropTarget dt) { ! if (--nDropTargets == 0) { removeNativeDropTarget(); nativeDropTargetContext = 0; }
11-06-2004

EVALUATION WComponentPeer.removeDropTarget() should do if (--nDropTargets == 0) instead of if (nDropTargets-- == 0) mingyao.yang@Eng 2000-01-03 Fixed during data transfer rewrite and unification for ladybird and merlin. The reference counting was messed up in several different places. An emprical analysis of the new reference counting scheme shows that it is correct. david.mendenhall@eng 2000-02-08 No test case provided because none can be written. This bug can only be verified using a debugger, a tool such as Purify, or printfs. david.mendenhall@east 2001-03-12
08-02-2000