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