I'm having trouble with memory in a j2me application. (see another question)
I discovered that one class has a loop that doesn't stop until the application is closed. This loop is consuming all the memory available.
I didn't make this class so I don't know why things was done this way. So any suggestions are welcome.
Here is a simplified version of the class:
import java.util.TimerTask;
public class SomeClass extends TimerTask implements Runnable {
private boolean running = false;
private Thread thread;
public void invokeThread() {
running = true;
thread = new Thread(this);
thread.start();
}
public void run() {
while(running) {
try {
Thread.sleep(800);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
doSomeStuff();
}
}
private void doSomeStuff() {
// do some stuff that consumes my memory
}
public void dispose() {
running = false;
}
}
Another class calls SomeClass.invokeThread() and wait for some user response (this already spend some memory).
When the users ends inputting data this another class calls dispose() and the while loop doesn't stop, wait some minutes or try to navigate a bit more the application and you get an OutOfMemoryError.
Can you help me?
thanks