If I declare an int (or any primitive type) within a method in Java, is that memory freed the moment the function returns, or does it have to hang around until the garbage c
is that memory freed the moment the function returns, or does it have to hang around until the garbage collector cleans it?
The primitives declared inside the method are stored on the stack frame of that method. Since the stack frame is destroyed as soon as the method returns, the space allocated to local variables are freed.