Difference between revisions of "Garbage collection (computer science)"

From Conservapedia
Jump to navigation Jump to search
(just a definition for now)
 
(expand)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
−
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. <ref> {{cite web|url=http://dictionary.reference.com/browse/garbage+collection?jss=0 | title=Garbage collection }} </ref>
+
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.<ref>{{cite web|url=http://dictionary.reference.com/browse/garbage+collection?jss=0 | title=Garbage collection }}</ref>
 +
 
 +
==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==
 +
*[[Java]]
 +
*[[C Sharp|C#]]
 +
*[[Python (programming language)|Python]]
 +
 
 +
== 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 [[reference]]d 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.
 +
 
 +
[[Category:Computers]]
 +
[[Category:Computer Programming]]
 +
[[Category:Computer Science]]
  
 
==References==
 
==References==
−
<references>
+
<references/>

Latest revision as of 18:25, October 30, 2023

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