I've got a kiosk-type program that displays small(<1K) HTML pages repeatedly
using the JEditorPane setText() method.  The problem I have is that HTML
pages that contain 'TABLE' tags with a 'width' attribute seem to cause a
memory leak that leads to the JVM running out of memory eventually.

This happens on WinNT and Win95 using either JDK 1.2.2 or 1.3_02.

I've attached a small program that demonstrates this problem. Displaying the
TABLE without the width attribute will work indefinitely.  Using the width
attribute, memory usage goes up and up.  

Does anyone have any ideas how to get around this or alternatives to the
JEditorPane for displaying HTML?

TIA,

Mike




File:  EPTest.java


import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class EPTest extends JFrame
        {
        public JEditorPane              html_pane;

        public EPTest() {
                html_pane = new JEditorPane();
                html_pane.setContentType("text/html");
                html_pane.setEditable(false);
                getContentPane().add(html_pane, BorderLayout.CENTER);
                setSize(400,400);
        }

        private static void gc() {
                try {
                        System.gc();
                        Thread.currentThread().sleep(100);
                        System.runFinalization();
                        Thread.currentThread().sleep(100);
                        System.gc();
                        Thread.currentThread().sleep(100);
                        System.runFinalization();
                        Thread.currentThread().sleep(100);
                } catch (Exception e) {
                        e.printStackTrace();
                }
        }

        public static void main(String [] args) {
                String str1 = new String("<HTML>" +
                                                "<BODY><TABLE width='100%'>"
+               // causes leak
                                //              "<BODY><TABLE>" +
// works fine
                                                "<TR><TD colspan='2'>ONE
HEADER</TD></TR>" +
        
"<TR><TD>1</TD><TD>Apple</TD></TR>" +
        
"<TR><TD>2</TD><TD>Orange</TD></TR>" +
        
"<TR><TD>3</TD><TD>Pear</TD></TR>" +
                                                "</TABLE></BODY>" +
                                                "</HTML>");
                EPTest eptest = new EPTest();
                eptest.setVisible(true);
                int loop = 0;
                while (true) {
                        loop++;
                        eptest.html_pane.setText(str1);
                        try {
                                Thread.sleep(1000);
                        }
                        catch (Exception e) {
                                e.printStackTrace();
                        }
                        if (loop % 10 == 0) {
                                System.out.println("Loop: " + loop);
                                gc();
                                Runtime rt = Runtime.getRuntime();
                                int used = (int)(rt.totalMemory() -
rt.freeMemory());
                                System.out.println("Memory: " + (used /
1000) + "/" + 
        
(rt.totalMemory() / 1000) + "K");
                        }
                }
        }
}
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to