Function: garbage-collect

garbage-collect is an interactive function defined in alloc.c.

Signature

(garbage-collect)

Documentation

Reclaim storage for Lisp objects no longer needed.

Garbage collection happens automatically if you cons more than gc-cons-threshold bytes of Lisp data since previous garbage collection. It returns the same info as garbage-collect-heapsize.

Note that calling this function does not guarantee that absolutely all unreachable objects will be garbage-collected. Emacs uses a mark-and-sweep garbage collector, but is conservative when it comes to collecting objects in some circumstances.

For further details, see Info node (elisp)Garbage Collection.

View in manual

Probably introduced at or before Emacs version 1.10.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/alloc.c
{
  if (garbage_collection_inhibited)
    return Qnil;

  specpdl_ref count = SPECPDL_INDEX ();
  specbind (Qsymbols_with_pos_enabled, Qnil);
  garbage_collect ();
  unbind_to (count, Qnil);
  return Fgarbage_collect_heapsize ();
}