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

Java Plugin memory leak when pumping liveconnect with data transfers from applet

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP Professional 2002, Service Pack 2


      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Internet Explorer 6.0.2900.2180

      A DESCRIPTION OF THE PROBLEM :
      Transfer of extensive amounts of data thru a liveconnect connection, either when getting data from javascript or when javascript gets data from an applet, leads eventually to a fast ie slow memory overflow, depending on the amount of data that is sent or received in each cycle. Apparently the system - ie. the internet explorer and/or the JVM - are not consistently releasing the memory after being used (see sample code below).

      We have tested two scenarios:

      the first one when a js script gets data from its applet using a js timer (see JavascriptToJava.html below) and then iterating this data (array) in local js function, here process(). This leads to the applet ending abruptedly within a minute timeframe without an exception track.

      in the second scenario the data is allocated by the applet and returned to the js thru a thread running on the applet. the js iterates this data again in a local process() - as in the scenario above. In this case the memory slowly grows in JVM until an out of memory exception is thrown.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Open with the IE the file JavascriptToJava.html. Repeat for JavaToJavascript.html. After starting, the IE loads the applet and the tests begin. Please open the windows task manager to monitor the memory usage.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      In both scenarios, after the IE or JVM hace depleted their memory, to release any unused buffers, letting the apllication run indefinetely.
      ACTUAL -
      See descriptiomn above. the applications terminates unexpectedly.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      in the first scenario there is no error message. in the second scenario a plugin exception (out of memory)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      scenario 1 - JavaScriptTojava.html:
      ============================
      <html>
      <head>
      <script type="text/javascript">

      function process(arr) {
      try {
      var sum = 0;
      for (var i = 0; i < arr.length; i++) {
      sum += arr[i];
      }
      document.getElementById("div1").firstChild.nodeValue = new Date() + ": sum=" + sum;
      } catch (e) {
      alert("Error process: " + e.name + ", " + e.message);
      }
      }

      function run() {
      var applet = document.getElementById("applet1");
      process(applet.newIntArray(10000));
      setTimeout("run()", 500);
      }

      </script>
      </head>
      <body onload="run()">
      <h1>Javascript to Java</h1>
      <applet id="applet1" code="MemoryLeakApplet.class" mayscript="mayscript">
      <param name="java_arguments" value="-Xms32m -Xmx32m">
      </applet>
      <div id="div1">init</div>
      </body>
      </html>

      Scenario 2: JavaToJavascript.html
      ============================
      <html>
      <head>
      <script type="text/javascript">

      function process(arr) {
      try {
      var sum = 0;
      for (var i = 0; i < arr.length; i++) {
      sum += arr[i];
      }
      document.getElementById("div1").firstChild.nodeValue = new Date() + ": sum=" + sum;
      } catch (e) {
      alert("Error process: " + e.name + ", " + e.message);
      }
      }

      function startJava() {
      var applet = document.getElementById("applet1");
      applet.startThread();
      }

      </script>
      </head>
      <body onload="startJava()">
      <h1>Java to Javascript</h1>
      <applet id="applet1" code="MemoryLeakApplet.class" mayscript="mayscript">
      <param name="java_arguments" value="-Xms32m -Xmx32m">
      </applet>
      <div id="div1">init</div>
      </body>
      </html>


      Java Code
      ========
      import javax.swing.JApplet;

      import netscape.javascript.JSObject;

      /**
       * JavaToJavascriptApplet.java
       *
       * © 2009 Fraport AG
       */

      /**
       * @author Marijo Basic, Marcelo Krebber, Alexander Schönberg
       *
       */
      public class MemoryLeakApplet extends JApplet {

      private static final long serialVersionUID = 1L;

      private static final int length = 50000;

      public void startThread() {
      Thread thread = new Thread() {
      @Override
      public void run() {
      while (true) {
      JSObject win = (JSObject) JSObject
      .getWindow(MemoryLeakApplet.this);
      win.call("process", new Object[] { newIntArray(length) });
      try {
      Thread.sleep(500);
      } catch (InterruptedException e) {
      e.printStackTrace();
      }
      }
      }
      };
      thread.start();
      }

      public int[] newIntArray(int length) {
      return new int[length];
      }

      }


      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      no bypassing known to us.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                nikgor Nikolay Gorshkov
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: