Good version:
- Code: Select all
import lejos.nxt.LCD;
public class MemTest {
private static String M = "M:";
public static void main(String[] args) {
while (true) {
LCD.clear();
LCD.drawString(M, 0, 7);
LCD.drawInt((int)Runtime.getRuntime().freeMemory(), 5, 3, 7);
LCD.refresh();
try {
Thread.sleep(1);
}
catch (InterruptedException ie) {
//oops
}
}
}
}
The leaky version:
- Code: Select all
public class MemTest {
private static Display display = new Display();
public static void main(String[] args) {
while (true) {
display.updateDisplay();
try {
Thread.sleep(1);
}
catch (InterruptedException ie) {
//oops
}
}
}
}
import lejos.nxt.LCD;
public class Display {
private static final String M = "M:";
public void updateDisplay() {
LCD.clear();
LCD.drawString(M, 0, 7);
LCD.drawInt((int)Runtime.getRuntime().freeMemory(), 5, 3, 7);
LCD.refresh();
}
}
Everything is declared static, exact same operations on the lejos APIs, can't see where I'm leaking from.

