Function: garbage-collect-maybe

garbage-collect-maybe is a function defined in alloc.c.

Signature

(garbage-collect-maybe FACTOR)

Documentation

Call garbage-collect if enough allocation happened.

FACTOR determines what "enough" means here: If FACTOR is a positive number N, it means to run GC if more than
1/Nth of the allocations needed to trigger automatic allocation took
place. Therefore, as N gets higher, this is more likely to perform a GC. Returns non-nil if GC happened, and nil otherwise.

Probably introduced at or before Emacs version 28.1.

Source Code

// Defined in /usr/src/emacs/src/alloc.c
{
  CHECK_FIXNAT (factor);
  EMACS_INT fact = XFIXNAT (factor);

  EMACS_INT since_gc = gc_threshold - consing_until_gc;
  if (fact >= 1 && since_gc > gc_threshold / fact)
    {
      garbage_collect ();
      return Qt;
    }
  else
    return Qnil;
}