As far as I understand, there are two fundamental approaches to garbage collection:
- Copying collectors
- Mark-and-sweep
Both algorithms are described in this article . According to the second algorithm, the author writes:
- Objects are allocated in memory.
- GC needs to run
- Application is suspended
- The collector walks through the object tree, marking live objects.
- The collector traverses the entire memory, finding all unchecked chunks of memory, storing them in the "free list"
- When new objects begin to allocate, they are allocated to the memory available in the "free list"
If I understand correctly, the objects that need to be deleted are transferred to the "free list". But where, in fact, is the removal of these objects? Or are they clearly not deleted, but simply overwritten when creating new objects?