]>
Commit | Line | Data |
---|---|---|
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 | 8 | malloc_trim \- release free memory from the heap |
0f03517a AC |
9 | .SH LIBRARY |
10 | Standard 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 |
19 | The | |
20 | .BR malloc_trim () | |
0deebbe5 | 21 | function attempts to release free memory from the heap |
a15b0e60 MK |
22 | (by calling |
23 | .BR sbrk (2) | |
0deebbe5 CD |
24 | or |
25 | .BR madvise (2) | |
26 | with suitable arguments). | |
847e0d88 | 27 | .PP |
a15b0e60 MK |
28 | The |
29 | .I pad | |
30 | argument specifies the amount of free space to leave untrimmed | |
31 | at the top of the heap. | |
32 | If this argument is 0, only the minimum amount of memory is maintained | |
33 | at the top of the heap (i.e., one page or less). | |
34 | A nonzero argument can be used to maintain some trailing space | |
35 | at the top of the heap in order to allow future allocations | |
36 | to be made without having to extend the heap with | |
37 | .BR sbrk (2). | |
38 | .SH RETURN VALUE | |
39 | The | |
40 | .BR malloc_trim () | |
41 | function returns 1 if memory was actually released back to the system, | |
42 | or 0 if it was not possible to release any memory. | |
43 | .SH ERRORS | |
44 | No errors are defined. | |
0cc0b5e4 ZL |
45 | .SH ATTRIBUTES |
46 | For an explanation of the terms used in this section, see | |
47 | .BR attributes (7). | |
48 | .TS | |
49 | allbox; | |
c466875e | 50 | lbx lb lb |
0cc0b5e4 ZL |
51 | l l l. |
52 | Interface Attribute Value | |
53 | T{ | |
9e54434e BR |
54 | .na |
55 | .nh | |
0cc0b5e4 ZL |
56 | .BR malloc_trim () |
57 | T} Thread safety MT-Safe | |
58 | .TE | |
847e0d88 | 59 | .sp 1 |
3113c7f3 | 60 | .SH STANDARDS |
4131356c AC |
61 | GNU. |
62 | .SH VERSIONS | |
63 | glibc 2.0. | |
a15b0e60 | 64 | .SH NOTES |
0deebbe5 | 65 | Only the main heap (using |
09358e73 MK |
66 | .BR sbrk (2)) |
67 | honors the | |
68 | .I pad | |
69 | argument; thread heaps do not. | |
0deebbe5 CD |
70 | .PP |
71 | Since glibc 2.8 this function frees memory in all arenas and in all | |
72 | chunks 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 |
77 | Before glibc 2.8 this function only freed memory at the |
78 | top 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) |