Garbage collection (computer science)

From Conservapedia
This is the current revision of Garbage collection (computer science) as edited by MayGodBless (talk | contribs) at 18:25, October 30, 2023. This URL is a permanent link to this version of this page.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In computer science, garbage collection is the process in which memory that was dynamically allocated during the execution of a program is reclaimed after its execution.[1]

Garbage Collection Algorithms

Mark and Sweep
The Mark and Sweep algorithm involves two phases. First, it marks all reachable objects in memory. Then, in the sweep phase, it reclaims memory occupied by unmarked (unreachable) objects. It's a simple yet effective technique.
Generational Garbage Collection
Generational garbage collection is based on the observation that most objects become unreachable shortly after they are created. It divides memory into multiple generations and prioritizes garbage collection in the younger generations, promoting objects that survive multiple collections to older generations.
Reference Counting
Reference counting maintains a reference count for each object. When an object's reference count drops to zero, it is considered unreachable and is deleted.
Copying and Compacting
This algorithm divides memory into two semi-spaces. Objects are initially allocated in one semi-space. When garbage collection occurs, reachable objects are copied to the other semi-space, and the memory is compacted. This approach is particularly effective for memory fragmentation.

Languages that use GC

Pointer Management

When an object is created memory is allocated for it and a pointer is created which refers to where this memory exists. A program counts each time the program requires this object as it might be referenced in many parts of the program. When no parts of the program are aware of the object both its reference and the memory given to it are cleared, making way for more objects to be created.

References