Page 1 of 1

What happens with the x variable in the "for" loop?

Posted: Mon Nov 30, 2015 5:59 am
by Heather
As we all know, JCVM doesn't have garbage collector. So in a for loop:

Code: Select all

for(short x=0;x<5;x++)
{
}

Does the x variable get utilized after the for loop, or it turns into garbage? What happens with the x variable in the for loop?

Re: What happens with the x variable in the "for" loop?

Posted: Mon Nov 30, 2015 6:25 am
by kuafu
x is a local variable , and its type is base type .So it's allocated in RAM. It will be recycled after the method or the block end. Its recycle is different with the reference type variable alloacated in EEPROM . It's recycle is faster . And most of the reference type is allocate in EEPROM, garbage the reference type cost much time.