]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_memleaks.3x
ncurses 6.4 - patch 20231111
[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.31 2023/11/11 11:46:43 tom Exp $
31 .TH curs_memleaks 3X 2023-11-11 "ncurses 6.4" "Library calls"
32 .ie \n(.g \{\
33 .ds `` \(lq
34 .ds '' \(rq
35 .\}
36 .el \{\
37 .ie t .ds `` ``
38 .el   .ds `` ""
39 .ie t .ds '' ''
40 .el   .ds '' ""
41 .\}
42 .
43 .de bP
44 .ie n  .IP \(bu 4
45 .el    .IP \(bu 2
46 ..
47 .SH NAME
48 \fB\%exit_curses\fP,
49 \fB\%exit_terminfo\fP \-
50 check for memory leaks in \fIcurses\fR
51 .SH SYNOPSIS
52 .nf
53 \fB#include <curses.h>
54 \fBvoid exit_curses(int \fIcode\fP);
55 .PP
56 \fB#include <term.h>
57 \fBvoid exit_terminfo(int \fIcode\fP);
58 .PP
59 \fI/* deprecated (intentionally not declared in curses.h or term.h) */
60 \fBvoid _nc_freeall(void);
61 \fBvoid _nc_free_and_exit(int \fIcode\fP);
62 \fBvoid _nc_free_tinfo(int \fIcode\fP);
63 .fi
64 .SH DESCRIPTION
65 These functions are used to simplify analysis of memory leaks in the ncurses
66 library.
67 .PP
68 Any implementation of curses must not free the memory associated with
69 a screen, since (even after calling \fB\%endwin\fP(3X)), it must be available
70 for use in the next call to \fB\%refresh\fP(3X).
71 There are also chunks of memory held for performance reasons.
72 That makes it hard to analyze curses applications for memory leaks.
73 When using the specially configured debugging version of the ncurses library,
74 applications can call functions which free those chunks of memory,
75 simplifying the process of memory-leak checking.
76 .PP
77 Some of the functions are named with a \*(``_nc_\*('' prefix
78 because they are not intended for use in the non-debugging library:
79 .TP 5
80 \fB\%_nc_freeall\fP
81 This frees (almost) all of the memory allocated by ncurses.
82 .TP 5
83 \fB\%_nc_free_and_exit\fP
84 This frees the memory allocated by ncurses (like \fB\%_nc_freeall\fP),
85 and exits the program.
86 It is preferred over \fB\%_nc_freeall\fP since some of that memory
87 may be required to keep the application running.
88 Simply exiting (with the given exit-code) is safer.
89 .TP 5
90 \fB\%_nc_free_tinfo\fP
91 Use this function if only the low-level terminfo functions (and
92 corresponding library) are used.
93 Like \fB\%_nc_free_and_exit\fP, it exits the program after freeing memory.
94 .PP
95 The functions prefixed \*(``_nc\*('' are normally not available;
96 they must be configured into the library
97 at build time using the \fB\%\-\-disable-leaks\fP option.
98 That compiles-in code that frees memory that normally would not be freed.
99 .PP
100 The \fB\%exit_curses\fP and \fB\%exit_terminfo\fP functions
101 call \fB\%_nc_free_and_exit\fP and \fB\%_nc_free_tinfo\fP if
102 the library is configured to support memory-leak checking.
103 If the library is not configured to support memory-leak checking,
104 they simply call \fBexit\fP.
105 .SH RETURN VALUE
106 These functions do not return a value.
107 .SH PORTABILITY
108 These functions are not part of X/Open Curses;
109 nor do other implementations of curses provide a similar feature.
110 .PP
111 In any implementation of X/Open Curses, an application can free part
112 of the memory allocated by curses:
113 .bP
114 The portable part of \fB\%exit_curses\fP can be freed using \fB\%delscreen\fP,
115 passing the \fBSCREEN*\fP pointer returned by \fB\%newterm\fP.
116 .IP
117 In some implementations, there is a global variable \fBsp\fP
118 which could be used, e.g., if the screen were only initialized
119 using \fB\%initscr\fP.
120 .bP
121 The portable part of \fB\%exit_terminfo\fP can be freed
122 using \fB\%del_curterm\fP.
123 .IP
124 In this case, there is a global variable \fB\%cur_term\fP which can be
125 used as parameter.
126 .SH SEE ALSO
127 \fB\%curses\fP(3X),
128 \fB\%curs_initscr\fP(3X),
129 \fB\%curs_terminfo\fP(3X)