Java ME Runnable object takes up memory although not made an instance yet
Posted
by
user1646684
on Stack Overflow
See other posts from Stack Overflow
or by user1646684
Published on 2012-09-04T16:37:31Z
Indexed on
2012/09/05
9:38 UTC
Read the original article
Hit count: 147
java-me
I am facing a strange problem with memory in Java ME.
here is a part of my code:
int variable=1;
while (true) {
if (variable==2) {
display = Display.getDisplay(this);
MyCanvas mc = new MyCanvas(this); // MyCanvas is a runnable object
mcT = new Thread(mc); // new thread for MyCanvas
mc.repaint();
display.setCurrent(mc);
mcT.start(); // run thread
}
if (variable==1) {
// Do some other stuff
}
}
The problem is that although still the variable
is set to 1
, so it does not come through the if (variable==2)
condition the program consumes 300kB more memory than when I delete the code after condition if (variable==2)
.
As far as I know the code should by executed and the objects shall be created only when I set variable to value 2
. But it consumes the memory also when the code after condition "if (variable==2)" is not executed.
Why does this happen?
© Stack Overflow or respective owner