1malloc_trim(3)             Library Functions Manual             malloc_trim(3)
2
3
4

NAME

6       malloc_trim - release free memory from the heap
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <malloc.h>
13
14       int malloc_trim(size_t pad);
15

DESCRIPTION

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

RETURN VALUE

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

ERRORS

32       No errors are defined.
33

ATTRIBUTES

35       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
36       tributes(7).
37
38       ┌────────────────────────────────────────────┬───────────────┬─────────┐
39Interface                                   Attribute     Value   
40       ├────────────────────────────────────────────┼───────────────┼─────────┤
41malloc_trim()                               │ Thread safety │ MT-Safe │
42       └────────────────────────────────────────────┴───────────────┴─────────┘
43

STANDARDS

45       GNU.
46

VERSIONS

48       glibc 2.0.
49

NOTES

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

SEE ALSO

61       sbrk(2), malloc(3), mallopt(3)
62
63
64
65Linux man-pages 6.05              2023-07-20                    malloc_trim(3)
Impressum