The mark-and-sweep algorithm