mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-02-05 16:44:47 +08:00
Prevent too much memory used by logging system
This commit is contained in:
parent
2f3c8285c8
commit
979a1a9810
@ -17,7 +17,6 @@
|
||||
*/
|
||||
package org.jackhuang.hmcl.ui;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.PrintStream;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.text.Document;
|
||||
@ -245,9 +244,17 @@ public class LogWindow extends javax.swing.JFrame {
|
||||
}
|
||||
|
||||
public void log(final String status, final Level c) {
|
||||
if (isVisible())
|
||||
return;
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
String newStatus = status.replace("\t", " ");
|
||||
Document d = txtLog.getStyledDocument();
|
||||
try { // prevent too much memory used.
|
||||
if (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() > 1l * 1024 * 1024 * 256)
|
||||
d.remove(0, d.getLength());
|
||||
} catch (Exception ex) {
|
||||
HMCLog.err("Failed to clear the text component", ex);
|
||||
}
|
||||
String newStatus = status.replace("\t", " ");
|
||||
SimpleAttributeSet sas = new SimpleAttributeSet();
|
||||
StyleConstants.setForeground(sas, c.COLOR);
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user