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