1malloc_trim(3) Library Functions Manual malloc_trim(3)
2
3
4
6 malloc_trim - release free memory from the heap
7
9 Standard C library (libc, -lc)
10
12 #include <malloc.h>
13
14 int malloc_trim(size_t pad);
15
17 The malloc_trim() function attempts to release free memory from the
18 heap (by calling sbrk(2) or madvise(2) with suitable arguments).
19
20 The pad argument specifies the amount of free space to leave untrimmed
21 at the top of the heap. If this argument is 0, only the minimum amount
22 of memory is maintained at the top of the heap (i.e., one page or
23 less). A nonzero argument can be used to maintain some trailing space
24 at the top of the heap in order to allow future allocations to be made
25 without having to extend the heap with sbrk(2).
26
28 The malloc_trim() function returns 1 if memory was actually released
29 back to the system, or 0 if it was not possible to release any memory.
30
32 No errors are defined.
33
35 For an explanation of the terms used in this section, see at‐
36 tributes(7).
37
38 ┌────────────────────────────────────────────┬───────────────┬─────────┐
39 │Interface │ Attribute │ Value │
40 ├────────────────────────────────────────────┼───────────────┼─────────┤
41 │malloc_trim() │ Thread safety │ MT-Safe │
42 └────────────────────────────────────────────┴───────────────┴─────────┘
43
45 GNU.
46
48 glibc 2.0.
49
51 Only the main heap (using sbrk(2)) honors the pad argument; thread
52 heaps do not.
53
54 Since glibc 2.8 this function frees memory in all arenas and in all
55 chunks with whole free pages.
56
57 Before glibc 2.8 this function only freed memory at the top of the heap
58 in the main arena.
59
61 sbrk(2), malloc(3), mallopt(3)
62
63
64
65Linux man-pages 6.05 2023-07-20 malloc_trim(3)