Version 41
Memory management allows us to create new objects and get rid of them; or more generally, to allocate chunks of memory — make them available to a program — and deallocate them — the program has no further use for it.
Early languages and memory management:
Exercise: using a free list, allocate and deallocate memory for two lists [a, b, c] and [d, e]:
x = cons(a, cons(b, cons(c, [])))
y = cons(d, cons(e, []))
free y
free x
Exercise: using a free list and reference counts, allocate and deallocate memory for two lists [a, b, c] and [d, e, b, c]:
x = cons(a, cons(b, cons(c)))
y = cons(d, cons(e, tail(x)))
x = y
x = []
GC preserves the live objects while reclaiming the space of all unused objects.
Exercise: using copy/compact GC, allocate and deallocate memory for two lists [a, b, c] and [d, e, b, c], and collect the garbage:
x = cons(a, cons(b, cons(c, [])))
y = cons(d, cons(e, tail(x)))
x = y
y = cons( ... oh i'm out of space ... 1, [])