mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-16 07:16:27 -04: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;
|
package org.jackhuang.hmcl.ui;
|
||||||
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.text.Document;
|
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) {
|
public void log(final String status, final Level c) {
|
||||||
|
if (isVisible())
|
||||||
|
return;
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
String newStatus = status.replace("\t", " ");
|
|
||||||
Document d = txtLog.getStyledDocument();
|
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();
|
SimpleAttributeSet sas = new SimpleAttributeSet();
|
||||||
StyleConstants.setForeground(sas, c.COLOR);
|
StyleConstants.setForeground(sas, c.COLOR);
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user