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

Memory Leak with Java Plug-In 1.3 using URLConnection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.3.1_01
    • Component/s: deploy
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      fcs
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: yyT116575 Date: 11/02/2000


      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
      Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)


      When using an applet that opens an URLConnection, the Browser's memory
      footprint increases with every URLConnection made. It seems to grow in
      parallel to the amount of data sent back through that connection.

      This leak has been experienced with IE 5.0, 5.01, 5.5, and Netscape 4.73 under
      both Windows NT4 and Windows 2000. This leak occurs under JRE 1.2.2 and JRE
      1.3.0.

      This is a very serious problem as it causes an applet used for monitoring
      purposes to eventually hog all memory resources.

      Following is an applet that demonstrates the memory leak. This applet makes a
      connection to an URL every two seconds.

      ===============================
      import java.net.*;
      import java.io.*;

      import javax.swing.*;

      public class ScoreboardApplet extends JApplet implements Runnable
      {
         public void init()
         {
            Thread t = new Thread(this);
            t.start();
         }

         public void run()
         {
            while (true)
            {
               Send("http://www.javasoft.com");
            }
         }

         public void Send(String s)
         {

            URL url = null;

            try
            {
               url = new URL(s);
            }
            catch (Exception e)
            {
            }

            InputStream in = null;
            URLConnection con = null;
            InputStreamReader ireader = null;
            BufferedReader breader = null;
            String line = null;

            try
            {
               con = url.openConnection();
               con.setDoInput(true);
               con.setDoOutput(false);
               con.setUseCaches(false);
               in = con.getInputStream();

               ireader = new InputStreamReader(in);
               breader = new BufferedReader(ireader);

               System.out.println("Lines:");
               while ((line = breader.readLine()) != null)
               {
                  System.out.print(".");
               }
               System.out.println();
            }
            catch (Exception e)
            {
               System.out.println("**** Connection/InputStream/Read Error");
               System.out.println(e.toString());
               e.printStackTrace();
            }
            finally
            {
               try
               {
                  if (in != null) in.close();
                  if (ireader != null) ireader.close();
                  if (breader != null) breader.close();
               }
               catch (IOException ioe)
               {
                  System.out.println("**** Couldn't close a Stream or Reader");
               }
               in = null;
               ireader = null;
               breader = null;
               con = null;
               line = null;
               url = null;
               System.gc();
            }
            try
            {
               Thread.currentThread().sleep(2000);
            }
            catch (Exception e)
            {
            }
         }
      }
      ===============================
      (Review ID: 111637)
      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            stanleyh Stanley Ho (Inactive)
            Reporter:
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: