1MALLOC_TRIM(3)             Linux Programmer's Manual            MALLOC_TRIM(3)
2
3
4

NAME

6       malloc_trim - release free memory from the heap
7

SYNOPSIS

9       #include <malloc.h>
10
11       int malloc_trim(size_t pad);
12

DESCRIPTION

14       The  malloc_trim()  function  attempts  to release free memory from the
15       heap (by calling sbrk(2) or madvise(2) with suitable arguments).
16
17       The pad argument specifies the amount of free space to leave  untrimmed
18       at the top of the heap.  If this argument is 0, only the minimum amount
19       of memory is maintained at the top of  the  heap  (i.e.,  one  page  or
20       less).   A nonzero argument can be used to maintain some trailing space
21       at the top of the heap in order to allow future allocations to be  made
22       without having to extend the heap with sbrk(2).
23

RETURN VALUE

25       The  malloc_trim()  function  returns 1 if memory was actually released
26       back to the system, or 0 if it was not possible to release any memory.
27

ERRORS

29       No errors are defined.
30

ATTRIBUTES

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

CONFORMING TO

42       This function is a GNU extension.
43

NOTES

45       This  function  is  automatically  called by free(3) in certain circum‐
46       stances; see the discussion of M_TOP_PAD and M_TRIM_THRESHOLD  in  mal‐
47       lopt(3).
48
49       Only  the  main  heap  (using  sbrk(2)) honors the pad argument; thread
50       heaps do not.
51
52       Since glibc 2.8 this function frees memory in all  arenas  and  in  all
53       chunks with whole free pages.
54
55       Before glibc 2.8 this function only freed memory at the top of the heap
56       in the main arena.
57

SEE ALSO

59       sbrk(2), malloc(3), mallopt(3)
60

COLOPHON

62       This page is part of release 5.02 of the Linux  man-pages  project.   A
63       description  of  the project, information about reporting bugs, and the
64       latest    version    of    this    page,    can     be     found     at
65       https://www.kernel.org/doc/man-pages/.
66
67
68
69Linux                             2019-05-09                    MALLOC_TRIM(3)
Impressum