A garbage collector automatically frees up memory that a program isn't using anymore.
For example, say we did this in Python:
# NOTE: this is NOT the fastest
# way to get the min!
nums_sorted = sorted(nums)
my_nums = [5, 3, 1, 4, 6]
Look at nums_sorted in get_min. We allocate that whole list inside our function, and once the function returns we don't need the list anymore. In fact, once the function returns we don't have any references to it anymore!
What happens to that list in memory? The Python garbage collector will notice we don't need it anymore and free up that space.
In some lower-level languages, like C, we don't have a garbage collector. So we need to manually free up any memory we're not using anymore:
// make a string that can hold 15 characters
// including the terminating null byte ('\0')
str = malloc(15);
// ... do some stuff with it ...
// we're done. free that memory!
We sometimes call this manual memory management.
Some languages, like C++, have both manual and automatic memory management.