3

I was reading some book about programming language and all of a sudden faced with this part:

Local variables are declared inside methods, and they only exist during the execution of that method, and once the method returns, the memory allocated to any local variables is released

my question is about the following part: "the memory allocated to any local variables is released" 1- Is "memory allocated" is originally "memory is allocated"?

2- What does exactly the part "the memory allocated to any local variables is released" means? Does it mean that a particular amount of space should be given to local variables?

1 Answer 1

8

The memory allocated is best understood as The memory that has been allocated.

Does it mean that a particular amount of space should be given to local variables?

It means the opposite. Whenever the method is executed, memory is allocated for the variables that have been declared inside the method. A simplified explanation is that space on a microchip has been reserved for the data that each variable "contains." No other data will be stored there as long as the method exists.

When the method returns, the reserved memory is "released." This means that the application no longer has a record of the variable, and it is free to allocate the memory to any other data that needs it.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .