]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_memleaks.3x
ncurses 6.4 - patch 20230923
[ncurses.git] / man / curs_memleaks.3x
1 .\"***************************************************************************
2 .\" Copyright 2019-2022,2023 Thomas E. Dickey                                *
3 .\" Copyright 2008-2010,2017 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_memleaks.3x,v 1.25 2023/09/23 21:07:59 tom Exp $
31 .TH curs_memleaks 3X 2023-09-23 "ncurses 6.4" "Library calls"
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de bP
37 .ie n  .IP \(bu 4
38 .el    .IP \(bu 2
39 ..
40 .SH NAME
41 \fB\%exit_curses\fP,
42 \fB\%exit_terminfo\fP \-
43 check for memory leaks in \fIcurses\fR
44 .SH SYNOPSIS
45 .nf
46 \fB#include <curses.h>\fP
47 \fBvoid exit_curses(int \fIcode\fB);\fR
48 .PP
49 \fB#include <term.h>\fP
50 \fBvoid exit_terminfo(int \fIcode\fB);\fR
51 .PP
52 /* deprecated (intentionally not declared in curses.h or term.h) */
53 \fBvoid _nc_freeall(void);\fP
54 \fBvoid _nc_free_and_exit(int \fIcode\fB);\fR
55 \fBvoid _nc_free_tinfo(int \fIcode\fB);\fR
56 .fi
57 .SH DESCRIPTION
58 These functions are used to simplify analysis of memory leaks in the ncurses
59 library.
60 .PP
61 Any implementation of curses must not free the memory associated with
62 a screen, since (even after calling \fB\%endwin\fP(3X)), it must be available
63 for use in the next call to \fB\%refresh\fP(3X).
64 There are also chunks of memory held for performance reasons.
65 That makes it hard to analyze curses applications for memory leaks.
66 When using the specially configured debugging version of the ncurses library,
67 applications can call functions which free those chunks of memory,
68 simplifying the process of memory-leak checking.
69 .PP
70 Some of the functions are named with a \*(``_nc_\*('' prefix
71 because they are not intended for use in the non-debugging library:
72 .TP 5
73 \fB\%_nc_freeall\fP
74 This frees (almost) all of the memory allocated by ncurses.
75 .TP 5
76 \fB\%_nc_free_and_exit\fP
77 This frees the memory allocated by ncurses (like \fB\%_nc_freeall\fP),
78 and exits the program.
79 It is preferred over \fB\%_nc_freeall\fP since some of that memory
80 may be required to keep the application running.
81 Simply exiting (with the given exit-code) is safer.
82 .TP 5
83 \fB\%_nc_free_tinfo\fP
84 Use this function if only the low-level terminfo functions (and
85 corresponding library) are used.
86 Like \fB\%_nc_free_and_exit\fP, it exits the program after freeing memory.
87 .PP
88 The functions prefixed \*(``_nc\*('' are normally not available;
89 they must be configured into the library
90 at build time using the \fB\%\-\-disable-leaks\fP option.
91 That compiles-in code that frees memory that normally would not be freed.
92 .PP
93 The \fB\%exit_curses\fP and \fB\%exit_terminfo\fP functions
94 call \fB\%_nc_free_and_exit\fP and \fB\%_nc_free_tinfo\fP if
95 the library is configured to support memory-leak checking.
96 If the library is not configured to support memory-leak checking,
97 they simply call \fBexit\fP.
98 .SH RETURN VALUE
99 These functions do not return a value.
100 .SH PORTABILITY
101 These functions are not part of X/Open Curses;
102 nor do other implementations of curses provide a similar feature.
103 .PP
104 In any implementation of X/Open Curses, an application can free part
105 of the memory allocated by curses:
106 .bP
107 The portable part of \fB\%exit_curses\fP can be freed using \fB\%delscreen\fP,
108 passing the \fBSCREEN*\fP pointer returned by \fB\%newterm\fP.
109 .IP
110 In some implementations, there is a global variable \fBsp\fP
111 which could be used, e.g., if the screen were only initialized
112 using \fB\%initscr\fP.
113 .bP
114 The portable part of \fB\%exit_terminfo\fP can be freed using \fB\%del_curterm\fP.
115 .IP
116 In this case, there is a global variable \fB\%cur_term\fP which can be
117 used as parameter.
118 .SH SEE ALSO
119 \fB\%curs_initscr\fP(3X),
120 \fB\%curs_terminfo\fP(3X),
121 \fB\%curses\fP(3X)