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

Memory leak in runtime

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.3
    • hotspot
    • sparc
    • solaris_2.5.1



      Name: rm29839 Date: 11/25/97


      The java runtime continues to grow over time when running our application with
      JDK 1.1.3 on Solaris 2.5.1. The following code
      will grow the java runtime by over 1 MB in a 24 hour period:

      import java.util.*;
       
      public class testThreads extends Thread
      {
          public static final String vers = "1.0";
          private tThread [] threads = new tThread[25];
       
          public testThreads()
          {
              for (int i = 0; i < (threads.length / 2); i++)
              {
                  threads[i] = new tThread();
                  yield();
              }
              
              start();
          }
       
          public void run()
          {
              while (true)
              {
                  // check for dead threads
                  for (int i = 0; i < threads.length; i++)
                  {
                      if ((threads[i] != null) && (((Thread) threads[i]).isAlive() == false))
                      {
                          threads[i] = null;
                      }
                  }
                  
                  // check if a new thread needs created
                  for (int i = 0; i < threads.length; i++)
                  {
                      if (threads[i] == null)
                      {
                          threads[i] = new tThread();
                          yield();
                      }
                  }
       
                  System.gc();
                  
                  try
                  {
                      sleep(10000);
                  }
                  catch (InterruptedException ex)
                  {
                  }
              }
          }
       
          public static void main(String [] argv)
          {
              testThreads me = new testThreads();
              //me.join();
          }
          
          public class tThread extends Thread
          {
              private boolean run = true;
              public byte [] extraMem = new byte[2048];
              public String dummyStr1 = "1234567890abcdefghijklmnopqrstuvwxyz";
              public String dummyStr2 = "1234567890abcdefghijklmnopqrstuvwxyz";
              
              public tThread()
              {
                  setPriority(Thread.MAX_PRIORITY);
                  start();
              }
       
              public void run()
              {
                  Process proc;
                  String [] args = new String[3];
                  args[0] = "/bin/sh";
                  args[1] = "-c";
       
                  try
                  {
                      synchronized (vers)
                      {
                          args[2] = "sleep "+(new java.util.Random().nextInt() % 360);
                          proc = Runtime.getRuntime().exec(args);
                          try
                          {
                              sleep(1000);
                          }
                          catch (InterruptedException ex)
                          {
                          }
                          
                      }
                      
                      proc.getErrorStream().close();
                      proc.getInputStream().close();
                      proc.getOutputStream().close();
       
                      while (run == true)
                      {
                          try
                          {
                              int notused = proc.exitValue();
                              run = false;
                          }
                          catch (IllegalThreadStateException ex)
                          {
                              try
                              {
                                  sleep(20000);
                              }
                              catch(InterruptedException ex2)
                              {
                              }
                          }
                      }
                  }
                  catch (java.io.IOException e)
                  {
                      e.printStackTrace();
                  }
              }
          }
      }
      (Review ID: 20566)
      ======================================================================

            never Tom Rodriguez
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: