Function: malloc-trim

malloc-trim is an interactive function defined in alloc.c.

Signature

(malloc-trim &optional LEAVE-PADDING)

Documentation

Release free heap memory to the OS.

This function asks libc to return unused heap memory back to the operating system. This function isn't guaranteed to do anything, and is mainly meant as a debugging tool.

If LEAVE_PADDING is given, ask the system to leave that much unused space in the heap of the Emacs process. This should be an integer, and if not given, it defaults to 0.

This function returns nil if no memory could be returned to the system, and non-nil if some memory could be returned.

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/alloc.c
{
  int pad = 0;

  if (! NILP (leave_padding))
    {
      CHECK_FIXNAT (leave_padding);
      pad = XFIXNUM (leave_padding);
    }

  /* 1 means that memory was released to the system.  */
  if (malloc_trim (pad) == 1)
    return Qt;
  else
    return Qnil;
}