I made a little clock for a desktop widget in Java(the widget includes many other features as well). I checked the applications RAM usage in task manager to see that the clock was using 700+ MB of RAM. I disabled the clock and the RAM usage went down to about 60 MB. Here is the clocks code:
final int timeRun = 0;
new Thread()
{
public void run()
{
while(timeRun == 0)
{
Calendar cal = new GregorianCalendar();
int hour = cal.get(Calendar.HOUR);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
int AM_PM = cal.get(Calendar.AM_PM);
String day_night = "";
if (AM_PM == 1){
day_night = "PM";
}else{
day_night = "AM";
}
String time = hour + ":" + min + ":" + sec + " " + day_night;
Clock.setText(time);
}
}
}.start();
Why is it using so much RAM? How could I fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…