I am using leJos 0.2 alfa.
I have noticed a memory leak in LCD.drawString, here is a small class displaying the memory lost for each call:
- Code: Select all
import lejos.nxt.*;
/**
* Shows the memory leak in LCD.drawString
* @author Andrea Sterbini
*
*/
public class LCDdrawStringMemoryLeak {
public static void main(String[] args) {
int old, mem;
while (!Button.ENTER.isPressed()) {
LCD.clear();
old = (int)System.getRuntime().freeMemory();
LCD.drawString("LCD.drawString", 0, 0);
mem = (int)System.getRuntime().freeMemory();
LCD.drawInt(mem, 0, 1);
LCD.drawInt(old - mem, 0, 2);
LCD.refresh();
try {Thread.sleep(500);} catch (Exception e){}
}
Sound.playTone(440, 100);
}
}
I don't have an arm toolchain installed, thus I cannot track the error in the VM.
Anyway, the drawString code in the VM file nextvm/platform/nxt/native.c is:
- Code: Select all
...
case drawString_4Ljava_3lang_3String_2II_5V:
{
byte *p = word2ptr(paramBase[0]);
int len, i;
Object *charArray = (Object *) word2ptr(get_word(p + HEADER_SIZE, 4));
len = charArray->flags.arrays.length;
{
char buff[len + 1];
char *chars = ((char *) charArray) + HEADER_SIZE;
for (i = 0; i < len; i++)
buff[i] = chars[i + i];
buff[len] = 0;
display_goto_xy(paramBase[1], paramBase[2]);
display_string(buff);
}
}
return;
...
Perhaps the problem is with the dinamic allocation of vector 'buff'?
Could someone try to recompile it using a constant-sized buffer (e.g 255 chars)?
AndreaS

