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

Member assignment in finalize breaks garbage collection

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1
    • core-libs
    • x86
    • windows_2000



      Name: gm110360 Date: 08/09/2002


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

      FULL OPERATING SYSTEM VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      ADDITIONAL OPERATING SYSTEMS :

      Tested also on Linux/Sun with JDK 1.3.0, 1.3.1
      and occurs also there.




      A DESCRIPTION OF THE PROBLEM :
      A class that extends Thread and has a finalizer,
      and creates a new Object in the finalize method,
      and assigns this object to a member, creates a memory
      leak. Actually, the newly created Object seems
      to be never subject of any garbage collection.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the example.

      You may also try to throw a new Exception as indicator
      of a failure from the finalize method, or create the
      new Object not in the finalize method, but in
      a method called from the finalize method.




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Of course, the exepected result is that there is
      no leakage of memory.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      [GC 511K->241K(1984K), 0.0026914 secs]
      [GC 753K->447K(1984K), 0.0037021 secs]
      [GC 946K->649K(1984K), 0.0032532 secs]
      [GC 1161K->866K(1984K), 0.0032457 secs]
      [GC 1378K->1073K(1984K), 0.0032007 secs]
      [GC 1585K->1300K(1984K), 0.0031917 secs]
      [GC 1812K->1507K(2112K), 0.0031524 secs]
      [Full GC 1507K->1507K(2112K), 0.0184789 secs]
      [GC 2019K->1715K(3092K), 0.0026931 secs]
      [GC 2227K->1922K(3092K), 0.0033644 secs]
      [GC 2434K->2130K(3092K), 0.0033848 secs]
      [GC 2642K->2375K(3092K), 0.0031532 secs]
      [GC 2887K->2582K(3220K), 0.0035633 secs]
      [Full GC 2582K->2582K(3220K), 0.0246556 secs]
      [GC 3094K->2790K(4884K), 0.0028414 secs]
      [GC 3302K->2997K(4884K), 0.0034222 secs]
      [GC 3509K->3205K(4884K), 0.0034136 secs]
      [GC 3717K->3412K(4884K), 0.0035144 secs]
      [GC 3924K->3619K(4884K), 0.0038536 secs]
      [GC 4131K->3827K(4884K), 0.0033711 secs]
      [GC 4339K->4034K(4884K), 0.0034504 secs]
      [GC 4546K->4242K(4884K), 0.0033717 secs]
      [GC 4754K->4525K(5144K), 0.0033451 secs]
      [Full GC 4525K->4525K(5144K), 0.0365139 secs]
      [GC 5037K->4733K(8120K), 0.0027182 secs]
      [GC 5245K->4940K(8120K), 0.0034191 secs]
      [GC 5452K->5147K(8120K), 0.0033365 secs]
      [GC 5659K->5355K(8120K), 0.0033063 secs]
      [GC 5867K->5562K(8120K), 0.0033496 secs]
      [GC 6074K->5770K(8120K), 0.0032996 secs]
      [GC 6282K->5977K(8120K), 0.0033979 secs]
      [GC 6489K->6184K(8120K), 0.0033683 secs]
      [GC 6696K->6392K(8120K), 0.0032677 secs]
      [GC 6904K->6599K(8120K), 0.0033845 secs]
      [GC 7111K->6806K(8120K), 0.0033831 secs]
      [GC 7318K->7014K(8120K), 0.0034038 secs]
      [GC 7526K->7221K(8120K), 0.0034650 secs]
      [GC 7733K->7429K(8120K), 0.0034513 secs]
      [GC 7941K->7636K(8248K), 0.0034021 secs]
      [Full GC 7636K->7515K(8248K), 0.0791020 secs]
      [GC 8475K->7904K(13552K), 0.0055582 secs]
      [GC 8864K->8293K(13552K), 0.0063424 secs]
      [GC 9253K->8834K(13552K), 0.0058519 secs]
      [GC 9794K->9223K(13552K), 0.0064257 secs]
      [GC 10183K->9612K(13552K), 0.0064218 secs]
      [GC 10572K->10001K(13552K), 0.0064774 secs]
      [GC 10961K->10390K(13552K), 0.0063578 secs]
      [GC 11350K->10778K(13552K), 0.0062435 secs]
      [GC 11738K->11167K(13552K), 0.0062891 secs]
      [GC 12127K->11556K(13552K), 0.0063891 secs]
      [GC 12516K->11945K(13552K), 0.0063807 secs]
      [GC 12905K->12334K(13552K), 0.0063536 secs]
      [GC 13294K->12723K(13808K), 0.0064061 secs]
      [Full GC 12723K->12723K(13808K), 0.0937628 secs]
      [GC 14259K->13345K(22872K), 0.0088975 secs]
      [GC 14881K->13967K(22872K), 0.0101722 secs]
      [GC 15503K->14589K(22872K), 0.0100021 secs]
      [GC 16125K->15211K(22872K), 0.0100566 secs]
      [GC 16747K->15834K(22872K), 0.0100795 secs]
      [GC 17370K->16456K(22872K), 0.0101044 secs]
      [GC 18504K->17590K(22872K), 0.0109128 secs]
      [GC 19126K->18212K(22872K), 0.0100345 secs]
      [GC 19748K->18834K(22872K), 0.0100474 secs]
      [GC 20370K->19457K(22872K), 0.0100574 secs]
      [GC 20993K->20079K(22872K), 0.0104837 secs]
      [GC 21615K->20701K(22872K), 0.0103136 secs]
      [GC 22237K->21323K(22872K), 0.0103885 secs]
      [GC 22859K->21945K(23512K), 0.0101692 secs]
      [Full GC 21945K->21945K(23512K), 0.1477705 secs]
      [GC 24407K->22943K(39232K), 0.0724472 secs]
      [GC 25503K->23980K(39232K), 0.0172924 secs]
      [GC 26540K->25017K(39232K), 0.0167111 secs]
      [GC 27577K->26054K(39232K), 0.0167331 secs]
      [GC 28613K->27091K(39232K), 0.0168843 secs]
      [GC 29651K->28127K(39232K), 0.0168868 secs]
      [GC 30687K->29165K(39232K), 0.0168890 secs]
      [GC 31725K->30201K(39232K), 0.0168144 secs]
      [GC 32761K->31238K(39232K), 0.0169066 secs]
      [GC 33798K->32275K(39232K), 0.0169332 secs]
      [GC 34835K->33312K(39232K), 0.0168681 secs]
      [GC 35872K->34959K(39232K), 0.0157727 secs]
      [GC 37519K->35995K(39232K), 0.0170980 secs]
      [GC 38555K->37032K(39616K), 0.0171997 secs]
      [Full GC 37032K->37032K(39616K), 0.2440877 secs]
      [GC 40895K->38597K(65088K), 0.1194579 secs]
      [GC 42693K->40256K(65088K), 0.0279371 secs]
      [GC 44352K->41915K(65088K), 0.0267595 secs]
      [GC 46011K->43575K(65088K), 0.0277555 secs]
      [GC 47671K->45234K(65088K), 0.0271467 secs]
      [GC 49330K->46893K(65088K), 0.0281237 secs]
      [GC 50989K->48552K(65088K), 0.0267319 secs]
      [GC 52648K->50211K(65088K), 0.0272216 secs]
      [GC 54307K->51870K(65088K), 0.0274404 secs]
      [GC 55966K->53529K(65088K), 0.0274353 secs]
      [GC 57625K->55188K(65088K), 0.0286316 secs]
      [GC 59284K->56848K(65088K), 0.0276759 secs]
      [Full GC 60944K->57610K(65088K), 0.5846732 secs]
      [Full GC 61706K->59269K(65088K), 0.4393980 secs]
      [Full GC 63365K->60928K(65088K), 0.4497781 secs]
      [Full GC 65087K->62613K(65088K), 0.4664302 secs]
      [Full GC 65087K->63615K(65088K), 0.4755554 secs]
      [Full GC 65087K->64212K(65088K), 0.4639861 secs]
      [Full GC 65087K->64566K(65088K), 0.4617632 secs]
      [Full GC 65087K->64778K(65088K), 0.4643624 secs]
      [Full GC 65087K->64903K(65088K), 0.4678628 secs]
      [Full GC 64903K->64903K(65088K), 0.4602415 secs]
      Exception in thread "main" java.lang.OutOfMemoryError

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Uberlauf extends Thread
      {
          String s;
          static long index;
          
          /**
           *
           * @return java.lang.String
           */
          final String nextName () {
              long res=nextIndex();
              return "hello" + Long.toString(res, 10);
          }

          final synchronized private static long nextIndex() { return index++; }

          Uberlauf()
          {
              s=nextName();
          }

          public static void main(String args[])
          {
              for(;;) {
                  Uberlauf u=new Uberlauf();
              }
          }

          public void finalize()
              throws Throwable
          {
              s=nextName();
              super.finalize();
          }
      }

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

      CUSTOMER WORKAROUND :
      None. You have to avoid this construct, which may
      be impossible when the object is an exception.
      (Review ID: 160567)
      ======================================================================

            mr Mark Reinhold
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: