OUTOFMEMORYERROR with LCD in while loop

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

OUTOFMEMORYERROR with LCD in while loop

Postby pawelp » Tue Jan 01, 2008 8:45 pm

Hello to everyone.

I've got simple piece od code:
After about 90 seconds it fails with OUTOFMEMORYERROR.
When I remove LCD methods it's OK.
Is it something wrong with LCD or maybe I use it wrong?

Any Idea?

Best regards
Pawel.



Code: Select all
import lejos.nxt.LCD;

public class WhileTest {

   /**
    * @param args
    * @throws Exception
    */
   public static void main(String[] args) throws Exception {
      while (true) {
         LCD.clearDisplay();
         LCD.drawString("Start", 2, 6);
         LCD.refresh();
         Thread.sleep(1);
      }
   }
}
pawelp
New User
 
Posts: 16
Joined: Fri Jun 01, 2007 8:34 pm

Postby edalquist » Tue Jan 01, 2008 9:32 pm

The "Start" string is created each time the loop iterates. Declare it outside of the loop or as a static class variable. Be careful though, there is/was a bug with things declared final leaking memory as well.

Most of my display code has a bunch of 'private static String' declarations at the top.
edalquist
Novice
 
Posts: 48
Joined: Sun Apr 08, 2007 5:55 pm

Postby pawelp » Tue Jan 01, 2008 10:01 pm

I forgot about it... Thanks.
Normally I work with java 5, where is String optimization.
In java 5 is created only one string in such code.

Best regards
Pawel
pawelp
New User
 
Posts: 16
Joined: Fri Jun 01, 2007 8:34 pm

Postby bbagnall » Wed Jan 02, 2008 2:28 am

The next version of leJOS NXJ coming out has a garbage collector so this type of error will no longer happen.
User avatar
bbagnall
Site Admin
 
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm


Return to NXJ Software

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests

more stuff