Look at the execution_table at step 2, what is the status of the object reference?
Aobj is set to null
Bobj points to a new object
Cobj still points to the object
Dobj is undefined
photo_cameraConcept Snapshot
Garbage Collection in Java:
- Objects created use memory.
- When no references point to an object, it becomes unreachable.
- Unreachable objects are marked for garbage collection.
- JVM frees memory by removing unreachable objects.
- System.gc() suggests JVM to run GC but does not guarantee immediate action.
contractFull Transcript
This visual execution shows how Java manages memory with garbage collection. First, an object is created and referenced by a variable. When the variable is set to null, the object has no references and becomes unreachable. The garbage collector then marks this object and frees its memory when System.gc() is called. This process helps keep memory clean and prevents leaks by removing objects no longer in use.