That I don't know, but I did notice that tempString is kept set between 
calls. And THAT isn't necessary.  I'm not quite sure why the variable is an 
instance variable. It seems only used within the method. I'd change the 
variable scope, too.

At 04:59 PM 4/6/2001 +0100, Neil Thorne wrote:
>I don't see how not nulling the temp string would lead to 166MB of memory.
>It only gets called 400 times...
>
>-----Original Message-----
>From: John Zukowski [mailto:[EMAIL PROTECTED]]
>Sent: 06 April 2001 16:53
>To: Pepelis, Aaron; [EMAIL PROTECTED]
>Subject: Re: memory leak... some one help, please!!
>
>
>
>You don't null out tempString between calls to append() so it keeps
>growing. A StringBuffer is probably your better data structure, but it too
>would need to be emptied between calls.
>
>J
>
>At 11:33 AM 4/6/2001 -0400, Pepelis, Aaron wrote:
>
> >why is there a memory leak in this?
> >it just keeps grow and growing and growing...
> >someone help me please... this brought a over night test up to 166MB of
> >memory usage...
> >thanks
> >aaron
> >
> >import javax.swing.*;
> >import java.awt.*;
> >import javax.swing.text.*;
> >
> >public class BufferedOutputArea extends JTextArea
> >{
> >
> >   private int size_of_buffer;
> >   private int cut_back = 0;
> >   String tempString;
> >   public BufferedOutputArea( int buffer)
> >   {
> >     this(buffer, 0);
> >   }
> >   public BufferedOutputArea( int buffer, int cut_back)
> >   {
> >     size_of_buffer = buffer;
> >     this.cut_back = cut_back;
> >   }
> >   public void setBufferSize(int buffer)
> >   {
> >     size_of_buffer = buffer;
> >   }
> >   public int getBufferSize()
> >   {
> >     return size_of_buffer;
> >   }
> >   public void append(String str)
> >   {
> >     tempString = getText()+str;
> >     super.append(str);
> >     if (tempString.length() > this.size_of_buffer)
> >     {
> >       try
> >       {
> >          System.out.println("hit  "+str + "\n" + size_of_buffer + " " +
> > cut_back + " " + tempString.length());
> >         // setText(getText(cut_back, tempString.length()));
> >          getDocument().remove(0,tempString.length() - this.size_of_buffer
> > + cut_back);
> >          System.out.println(""+getText().length());
> >
> >       }
> >       catch (BadLocationException e)
> >       {
> >       }
> >     }
> >     setCaretPosition(getText().length());
> >   }
> >
> >   public static void main(String [] args)
> >   {
> >     JFrame frame = new JFrame();
> >     BufferedOutputArea output = new BufferedOutputArea(5000, 2000);
> >     JScrollPane scroll = new JScrollPane(output);
> >     scroll.setAutoscrolls(true);
> >     frame.getContentPane().add(scroll);
> >     frame.setSize(500,500);
> >     frame.setVisible(true);
> >     output.append("hello you think\nthat you are so cool\njust because
> > your gnigg?\n");
> >     try
> >     {
> >       for (int i= 0; i < 400; i++)
> >       {
> >         output.append("fudge this out put " + i +
> >
>"\n3444444444444444444444444444444444444999999999999999999999999999999999999
>9999999999999999999999999999999999999999999999999999999999999999999999999999
>99999999999999999999999999999999999999999999999999999\n"
> > );
> >
> >         Thread.sleep(300);
> >       }
> >     }
> >     catch (Exception e)
> >     {
> >
> >     }
> >   }
> >}
>
>
>John Zukowski, Strategic Java Consulting
>JZ Ventures, Inc. - http://www.jzventures.com
>The limits of my language are the limits of my world - Wittgenstein
>
>
>_______________________________________________
>Swing mailing list
>[EMAIL PROTECTED]
>http://eos.dk/mailman/listinfo/swing
>
>
>**********************************************************************
>This email is intended only for the addressee. This email
>and any files transmitted with it may contain confidential
>or privileged information. If you are not the named
>addressee or the person responsible for delivering the
>message to the named addressee, please contact
>[EMAIL PROTECTED]
>
>This email has been scanned by MAILsweeper.
>**********************************************************************


John Zukowski, Strategic Java Consulting
JZ Ventures, Inc. - http://www.jzventures.com
The limits of my language are the limits of my world - Wittgenstein


_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to