\f
* Lisp Changes in Emacs 29.1
+---
+** New function 'malloc-trim'.
+This function allows returning unused memory back to the operating
+system, and is mainly meant as a debugging tool.
+
---
** 'x-show-tip' no longer hard-codes a timeout default.
The new 'x-show-tooltip-timeout' variable allows the user to alter
}
#endif
+#ifdef HAVE_MALLOC_TRIM
+DEFUN ("malloc-trim", Fmalloc_trim, Smalloc_trim, 0, 1, "",
+ doc: /* Release free memory from the heap.
+This function asks libc to return unused 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
+spaced in the heap. This should be an integer, and if not given,
+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. */)
+ (Lisp_Object leave_padding)
+{
+ 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;
+}
+#endif
+
static bool
symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj)
{
(__GLIBC__ > 2 || __GLIBC_MINOR__ >= 10)
defsubr (&Smalloc_info);
+#endif
+#ifdef HAVE_MALLOC_TRIM
+ defsubr (&Smalloc_trim);
#endif
defsubr (&Ssuspicious_object);