(defmethod gc-work-for-size ((heap heap) size)
;; The garbage collector needs to be ready when there's no more free space
;; left in the heap. So when SIZE octets are allocated, the garbage collector
;; needs to collect a proportional amount of bytes:
;;
;; Size / Free = Work / WorkLeft
;;
;; or: Work = (Size / Free) * WorkLeft
;;
(if (zerop size)
0
(let* ((free (free-space heap))
(work-left (work-left heap)))
(if (>= size free)
work-left
(floor (* size work-left) free)))))
Source Context