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 + 
> 
>"\n3444444444444444444444444444444444444999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\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

Reply via email to