是什么占掉了我的内存???
每一次从第一页跳转到第二页都会占掉大量的内存。。高手帮我看看是为什么啊??我觉得我并没有new新的对象啊。。。
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
public class TestMB extends MIDlet implements CommandListener {
Display display;
Form form1;
Form form2;
Ticker ticker1;
Calendar calendar1;
Date date;
Runtime runMemory;
static final Command okCommand = new Command("Info", Command.OK, 1);
static final Command backCommand = new Command("Back", Command.BACK, 0);
static final Command exitCommand = new Command("Exit", Command.EXIT, 2);
public TestMB() {
}
public void startApp() throws MIDletStateChangeException {
display = Display.getDisplay(this);
// 创建屏幕横向滚动文本ticker1
ticker1 = new Ticker("欢迎使用“小呜呜”程序!!");
form1 = new Form("查看时间和内存"); // 创造不带任何组建的空白form1
form2 = new Form("信息如下:"); // 创造不带任何组建的空白form2
StringItem strItem = new StringItem("软件描述:", "");
form1.append(strItem);// 添加第一页内容信息
form1.setTicker(ticker1);// 向第一页添加横向滚动条
showForm1();// 显示第一页
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void showForm1() {
form1.addCommand(exitCommand);
form1.addCommand(okCommand);
form1.setCommandListener(this);
display.setCurrent(form1);
}
public void showForm2() {
form2.addCommand(exitCommand);
form2.addCommand(backCommand);
form2.setCommandListener(this);
showInfo();
display.setCurrent(form2);
}
public void showInfo() {
form2.deleteAll();//在这里我删掉了所有的Item,内存应该会被回收啊??
//calendar1 = Calendar.getInstance();// 得到实例calendar1
//date = calendar1.getTime();
//form2.append(new StringItem(" ", "日期:" + date));
runMemory = Runtime.getRuntime();
form2.append(new StringItem(" ", "Total Memory:"
+ runMemory.totalMemory()));
form2.append(new StringItem(" ", "Free Memory:"
+ runMemory.freeMemory()));
}
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
} else if (label.equals("Back")) {
showForm1();
} else {
showForm2();
}
}
}