Debian Codegraph @

upstream/debian-unstable/man3/malloc_trim.3

raw
1 '\" t
2 .\" Copyright 2012, Michael Kerrisk <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH malloc_trim 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 malloc_trim \- release free memory from the heap
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <malloc.h>
16 .P
17 .BI "int malloc_trim(size_t " pad );
18 .fi
19 .SH DESCRIPTION
20 The
21 .BR malloc_trim ()
22 function attempts to release free memory from the heap
23 (by calling
24 .BR sbrk (2)
25 or
26 .BR madvise (2)
27 with suitable arguments).
28 .P
29 The
30 .I pad
31 argument specifies the amount of free space to leave untrimmed
32 at the top of the heap.
33 If this argument is 0, only the minimum amount of memory is maintained
34 at the top of the heap (i.e., one page or less).
35 A nonzero argument can be used to maintain some trailing space
36 at the top of the heap in order to allow future allocations
37 to be made without having to extend the heap with
38 .BR sbrk (2).
39 .SH RETURN VALUE
40 The
41 .BR malloc_trim ()
42 function returns 1 if memory was actually released back to the system,
43 or 0 if it was not possible to release any memory.
44 .SH ERRORS
45 No errors are defined.
46 .SH ATTRIBUTES
47 For an explanation of the terms used in this section, see
48 .BR attributes (7).
49 .TS
50 allbox;
51 lbx lb lb
52 l l l.
53 Interface Attribute Value
54 T{
55 .na
56 .nh
57 .BR malloc_trim ()
58 T} Thread safety MT-Safe
59 .TE
60 .SH STANDARDS
61 GNU.
62 .SH VERSIONS
63 glibc 2.0.
64 .SH NOTES
65 Only the main heap
66 (using
67 .BR sbrk (2))
68 honors the
69 .I pad
70 argument;
71 thread heaps do not.
72 .P
73 Since glibc 2.8 this function frees memory in all arenas and in all
74 chunks with whole free pages.
75 .\" See commit 68631c8eb92ff38d9da1ae34f6aa048539b199cc
76 .\" (dated 2007-12-16) which adds iteration over all
77 .\" arenas and frees all pages in chunks which are free.
78 .P
79 Before glibc 2.8 this function only freed memory at the
80 top of the heap in the main arena.
81 .SH SEE ALSO
82 .BR sbrk (2),
83 .BR malloc (3),
84 .BR mallopt (3)