Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4224888

java.awt.dnd.DropTarget causing JNI Global Reference leak?

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.2.0, 1.2.1
    • Fix Version/s: 1.2.2_003
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b03
    • CPU:
      x86, sparc
    • OS:
      solaris_7, windows_nt
    • Verification:
      Not verified

      Backports

        Description



        Name: vi73552 Date: 03/29/99


        Hi,

        I filed this bug on 28 January 1999. I'm refiling it as I haven't heard back from Vasya (for almost 1 month now) with regards to why he thought the bug I reported is a duplicate of bug 4109789. I'm not sure what else to do other than to refile this. I need to make sure that this one is not overlooked for the next JDK 1.2 release. Please note that the bug was originally found in JDK 1.2 FCS and bug 4109789 which Vasya said was the same bug was marked as fixed in JDK 1.2 Beta 4. Please see the included e-mail below for more detail. The original bug report is provided again below after the included e-mail.

        Please let me know if you have further questions. Without this fix, DnD on Win32 is almost useless for real applications.

        Thank you...

        -----
        >From: "Paul Tjahjadi" <###@###.###>
        >To: ###@###.###
        >CC: ###@###.###
        >Subject: Re: (Review ID: 53371) java.awt.dnd.DropTarget causing JNI Global Reference leak
        >Date: Tue, 09 Mar 1999 20:28:57 PST
        >
        >Hi,
        >
        >can you please let me know why bug 4109789 is saying that the bug was
        >fixed in JDK 1.2 Beta 4? The memory leak that I found is in the FCS
        >release of JDK 1.2 (which I assume is newer than Beta 4?). So I'm not
        >sure I understand how the bug report I submitted could be a duplicate if
        >it's still a problem in JDK 1.2 FCS?
        >
        >Thank you...
        >
        >pbt
        >
        >>From: vasya <###@###.###>
        >>To: ###@###.###
        >>Subject: Re: (Review ID: 53371) java.awt.dnd.DropTarget causing JNI
        >Global Reference leak?
        >>Date: Mon, 8 Mar 1999 20:50:39 -0800
        >>
        >>You have submitted a bug that is a duplicate of Bug Id: 4109789
        >>This bug may or may not be listed at the following web sites:
        >>
        >>Bug information is available through the Java Developer Connection.
        >> http://java.sun.com/jdc
        >>
        >>Thank you for providing us with additional information that can be used
        >>in the resolution of this bug.
        >>
        >>----------------- Original Bug Report-------------------
        >>
        >>id : 53371
        >>category : java
        >>subcategory : drag&drop
        >>type : bug
        >>synopsis : java.awt.dnd.DropTarget causing JNI Global Reference leak?
        >>comments : (company - , email - ###@###.###)
        >>workaround : None that I know of.
        >>cust_name : PTjahjadi
        >>cust_email : ###@###.###
        >>company : other
        >>release : 1.2
        >>hardware : x86
        >>OSversion : win_nt_4.0
        >>status : Deleted
        >>delReason : Duplicate
        >>priority : 4
        >>bugtraqID : 4109789
        >>dateCreated : 1999-01-28 16:36:06.0
        >>dateEvaluated : 1999-02-01 11:41:22.0
        -----

        Original bug report:

        =====
        Hi,

        it seems that the DropTarget addition and removal procedure in JDK 1.2 is causing a JNI Global Reference leak. Below is a simple test case which shows the problem. Please let me know if you know of any workarounds for it.

        Thank you...

        pbt

        // BEGIN --- bugDropTargetLeak.java
        /*
         * This simple Java application shows the memory leak that's caused due to a
         * JNI Global Reference when a DropTarget's component is set. It seems that
         * removeNativeDropTarget() is not properly cleaning up the global reference.
         *
         * To reproduce the problem, you will need to run the application like this on
         * Windows (assuming c:\jdk1.2 is your installation folder for JDK 1.2 FCS):
         *
         * c:\jdk1.2\bin\java -Xnoclassgc -Xrunhprof:file=dump.hprof,format=b bugDropTargetLeak
         *
         * After the application has started, follow these steps:
         * 1. Hit the `gc()' button two or three times.
         * 2. Go to the Java console and hit Ctrl-Break to dump the heap.
         * 3. Hit the `Click me to launch a leaked window' button which would create
         * a JFrame and attach a DropTarget to it.
         * 4. Close the JFrame (either by using Alt-F4 or clicking on the X button on
         * the title bar).
         * 5. Hit the `gc()' button two or three times again.
         * 6. Go to the Java console and hit Ctrl-Break to get the second heap dump.
         * 7. Quit the application.
         * 8. Start the HAT server using something like:
         * java -mx1004m hat.Main -port=7007 -baseline=dump.hprof:1 dump.hprof:2
         * If you drill down on the info for the instance of bugDropTargetLeak,
         * you'll see something like:
         *
         * JNI Global References
         * JNI Global Reference :
         * --> bugDropTargetLeak@0x4004a000[new] (264 bytes)
         *
         * This analysis concurs with the one OptimizeIt 3.0 shows after following
         * the same steps shown above.
         */

        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);
          }
        }
        // END --- bugDropTargetLeak.java
        =====
        (Review ID: 56228)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  myangsunw Mingyao Yang (Inactive)
                  Reporter:
                  vasya Vassili Igouchkine (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: