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

Memory Error using ObjectOutputStream

XMLWordPrintable



      Name: rm29839 Date: 11/03/97


      hello,

      It happens when using ObjectOutputStream for
      writing many objects. It seems that object aren't
      garbage collected after being saved. Closing
      the stream is a solution but...

      Thanks,
      Claude.

      The behavior is the same on Solaris

      >>> here is an example :

      class TestSave extends Thread{


        public static void main (String[] args){
      TestSave ts = new TestSave();
      ts.run();
      }
       

            try{
               ObjectOutputStream os= new ObjectOutputStream(new FileOutputStream(new File("try")));
               
               for (int t=0;t<5000;t++)
                  {
                     System.out.println( t );
                     MyBigObject mbo=new MyBigObject();
                     os.writeObject(mbo);
                     os.flush();
                  }
               os.close();
            }
            catch (Exception e){
               System.out.println("exception : " + e + " : " + e .getMessage());
            }
            
         }
         
      }


      class MyBigObject implements Serializable {

         byte[] b = null;

         MySubBigObject msbo= null;

         public MyBigObject()
         {
            b=new byte[2000];
            msbo=new MySubBigObject();
         }
         
      }

      class MySubBigObject implements Serializable {

         byte[] b = null;

         public MySubBigObject()
         {
            b=new byte[2000];
         }
         
      }


      >>>> and a trace

      ...
      ...
      3190
      3191
      3192
      3193
      3194
      3195
      3196
      3197
      3198
      java.lang.OutOfMemoryError:
      at java.io.ObjectOutputStream.assignWireOffset(ObjectOutputStream.java:786)
      at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:670)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:225)
      at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:325)
      at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:707)
      at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:225)
      at transdoc.TestSave.run(essai.java:32)
      (Review ID: 18618)
      ======================================================================

            jfialli Joe Fialli
            rmandelsunw Ronan Mandel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: