Garbage collection algorithm