ボタンが 1 つと 2 つしかない単純なアプリケーションを使用していJTextArea
ます。最初にアプリケーションがロードされると、約28MBのメモリが使用されます。文字列 (アラビア文字、文字列長 5000) を JTextArea に設定すると、メモリ使用量が270MBであり、それを解放していないことが示されています (このアプリでは、NetBeans がそれよりも少ない量を使用していることに気付きました)。そのメモリを使用しているファイルを開いていません。考えられる理由と、メモリ使用量を減らす方法を教えてください。
注: メモリ使用量はタスク マネージャーからのものです。
編集:
public class FileReadTest extends JFrame {
private JTextArea textArea;
private Jbutton readButton;
public FileReadTest() {
initialize();
}
private void initialize() {
setSize(300, 300);
setTitle("File Reader Test");
setLayout(new BorderLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textArea = new JTextArea();
textArea.setFont(new Font("Times New Roman", Font.Plain, 18))
JScrollPane scrollPane = new JScrollPane(textArea);
readButton=new JButton("ReadFrom File");
readButton.addActionListiner(new AvtionPerformed(ActionEvent ev) {
FileReader reader=null;
try {
//
// Read some text from file to display in
// the JTextArea.
//
reader=new FileReader("myfile.txt");
textArea.read(, null);
} catch (IOException e) {
e.printStackTrace();
}
finally {
try{
reader.close();
}
catch(Exception ex){}
}
}
getContentPane().add(scrollPane, BorderLayout.CENTER);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new FileReadTest().setVisible(true);
}
});
}
}
read
ボタンを押すか、テキストを手動でコピーして貼り付けても、大文字と小文字は同じです。