Storage bugs are hard to catch because the effect is far in time.
Garbage Collection was first introduced in Java in 1990 (although studied for Lisp in 1950s). It is very recent.
Automatic memory management is great but it reduces programmer's control. So if you want speed, better manage it yourself.
Memory leak is still possible (even likely when you forget to set a pointer that point to a root of large chunk of memory to
x is reachable if and only if
a register contain a pointer to
another reachable object
y contains a pointer to
If an object is reachable, doesn't mean it will be used.
If we garbage collect only when memory is full, then we have a problem since garbage collection algorithm itself may use memory.
pointer reversal: when a pointer is followed its is reversed to point to its parent (so that we can go back, we need 1 register)
free list: see 15213
Garbage collection must work with constant space.
Algorithm: like a frame buffer
This method provide less segmentation and is believed to be the fastest GC technique. Collection is relatively cheap since we only touch reachable objects.
Some language do not allow copying (C and C++). C and C++ have to use mark and sweep.
How to we tell if a memory region is a pointer? Well, we can't tell. But we can be conservative and keep everything that looks like a pointer.
point to valid address
we might overestimate the set of reachable object
easy to implement
avoid large pause in execution
cannot collect circular reference
manipulating reference count is slow
concurrent: allow program to run while the collection is happening
generational: do not scan long-lived object at every collection
real time: bound the length of pauses
parallel: several collectors working at the same time
Table of Content