Consider a simple while loop like below
public static void main(String[] args) {
int i = 6;
int k = 10;
while(i<k) {
int v = 5;
i++;
}
}
Is it true that the space for variable v is allocated only when the while loop is being executed and de-allocated when the loop ends?
Or does it stay in the memory regardless of the termination or execution of the while loop?
Is it any different if it is not a primitive data type(any kind of object)?