Next: Stack of activation records
Up: Unit 11
Previous: Run-time memory management
- An object is created by invoking a constructor by means of the
new operator. The moment an object is created, the memory locations
for the object are allocated on the heap.
- When an object is not used anymore by the program, the memory locations
allocated on the heap for the object can be freed and made available for
other objects. In Java, differently from other languages, the programmer
cannot choose to do such an operation explicitly. It is done automatically
by the garbage collector when the object is not accessible anymore.
The garbage collector is a component of the JVM that is able to detect
when an object has no more references that can be used to access the object,
and hence is not usable anymore and can be deallocated. Typically, the garbage
collector is invoked automatically by the JVM, without any control by the
programmer, when it is necessary to make memory available. However, the
programmer can also choose to invoke the garbage collector explicitly, by
calling the static method gc() of the class System.
Next: Stack of activation records
Up: Unit 11
Previous: Run-time memory management