tags:

views:

271

answers:

1

I have a Java applet (an actual <APPLET>) which generates frequent log messages to System.out. If the Java Console is enabled in the user's browser, it will of course retain references to all of these strings and prevent them from being garbage collected. The problem is the number of log messages the console retains: the applet heap grows very quickly. After four days of running, it will throw an OutOfMemory exception. So far as I can tell from jmap and jhat, the log strings represent the majority of its footprint.

Is there an API to more tightly limit the number or total size of messages retained by the Java Console? In case of an error I'd only need the most recent few messages. The Console does start retiring the oldest messages at some point, but only after it has grown really huge.

I realize that "don't start the console" or "just clear the console" are possible solutions, but have you ever tried asking a non-technical user whether they have the Java Console enabled? Or try to walk them through viewing and clearing it? I really would like them to leave the console enabled, so I can see the messages if there is an error.

+1  A: 

Instead of System.out.println use java.util.logging. It is much easier to change log levels later and decrease the number of log messages.

Also check MemoryHandler, it uses a buffer and discards old log messages automatically.

asalamon74