Created: 2023-01-15 19:01
Status: #concept
Subject: Programming
Tags: C Memory Byte Memory Addresses Pointers Dynamic Memory Allocation

Garbage

Description

  • Garbage is allocated Memory Bytes that are no longer being utilized by the program, but stays allocated due to not being "collected" or "freed".
  • Leaving Garbage behind can lead to Memory Leaks.
  • Other languages have a Garbage Collector — which managers Garbage, but C does not and programmers must manually deallocate memory using the free() Function to remove the garbage.

C Example

p = malloc(...); // allocates a memory block and assigns it to *p
q = malloc(...); // allocates a memory block and assigns it to *q
p = q; // assigns *p to point to the block pointed by *q, leaving *p's block alone

Memory Garbage Illustration pt.1.png
Memory Garbage Illustration pt.2.png

References