Social Sciences, asked by mdarman6996, 10 months ago

Explain garbage collection and compaction methods with an example.

Answers

Answered by ggghh76
2

Garbage collection (GC) is a dynamic approach to automatic memory management and heap allocation that processes and identifies dead memory blocks and reallocates storage for reuse. The primary purpose of garbage collection is to reduce memory leaks.

GC implementation requires three primary approaches, as follows:

Mark-and-sweep - In process when memory runs out, the GC locates all accessible memory and then reclaims available memory.

Reference counting - Allocated objects contain a reference count of the referencing number. When the memory count is zero, the object is garbage and is then destroyed. The freed memory returns to the memory heap.

Similar questions