next up previous
Next: Definition of methods Up: Unit 03 Previous: Scope of instance variables

Lifetime of instance variables

The lifetime of an instance variable coincides precisely with the lifetime of the object of which it is part. The instance variables are created the moment the object containing them is created, and they can be used as long as the object can be accessed. The creation of the object denoted by a variable is done by the run-time support (the Java Virtual Machine), by allocating, together with the object, the memory that is necessary to store the values of its instance variables.

Through the mechanism of garbage collection, the run-time support automatically destroys an object (and frees the memory it takes up) when there are no more references to the object, and hence the object cannot be accessed any more.


next up previous
Next: Definition of methods Up: Unit 03 Previous: Scope of instance variables