blob: 0626d774097b6196d6084becf3f4b25ee2b4ae5d [file] [log] [blame]
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05301.\"***************************************************************************
micky3879b9f5e72025-07-08 18:04:53 -04002.\" Copyright 2019-2023,2024 Thomas E. Dickey *
3.\" Copyright 2008-2010,2017 Free Software Foundation, Inc. *
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +05304.\" *
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.\"
micky3879b9f5e72025-07-08 18:04:53 -040030.\" $Id: curs_memleaks.3x,v 1.35 2024/03/16 15:35:01 tom Exp $
31.TH curs_memleaks 3X 2024-03-16 "ncurses @NCURSES_MAJOR@.@NCURSES_MINOR@" "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..
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053047.SH NAME
micky3879b9f5e72025-07-08 18:04:53 -040048\fB\%exit_curses\fP,
49\fB\%exit_terminfo\fP \-
50check for memory leaks in \fIcurses\fR
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053051.SH SYNOPSIS
micky3879b9f5e72025-07-08 18:04:53 -040052.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
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053064.SH DESCRIPTION
micky3879b9f5e72025-07-08 18:04:53 -040065These functions are used to simplify analysis of memory leaks in the
66\fI\%ncurses\fP library.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053067.PP
68Any implementation of curses must not free the memory associated with
micky3879b9f5e72025-07-08 18:04:53 -040069a screen, since (even after calling \fB\%endwin\fP(3X)), it must be available
70for use in the next call to \fB\%refresh\fP(3X).
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053071There are also chunks of memory held for performance reasons.
72That makes it hard to analyze curses applications for memory leaks.
micky3879b9f5e72025-07-08 18:04:53 -040073When using the specially configured debugging version of the
74\fI\%ncurses\fP library,
75applications can call functions which free those chunks of memory,
76simplifying the process of memory-leak checking.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +053077.PP
micky3879b9f5e72025-07-08 18:04:53 -040078Some of the functions are named with a \*(``_nc_\*('' prefix
79because they are not intended for use in the non-debugging library:
80.TP 5
81\fB\%_nc_freeall\fP
82This frees (almost) all of the memory allocated by \fI\%ncurses\fP.
83.TP 5
84\fB\%_nc_free_and_exit\fP
85This frees the memory allocated by \fI\%ncurses\fP
86(like \fB\%_nc_freeall\fP),
87and exits the program.
88It is preferred over \fB\%_nc_freeall\fP since some of that memory
89may be required to keep the application running.
90Simply exiting (with the given exit-code) is safer.
91.TP 5
92\fB\%_nc_free_tinfo\fP
93Use this function if only the low-level terminfo functions (and
94corresponding library) are used.
95Like \fB\%_nc_free_and_exit\fP, it exits the program after freeing memory.
96.PP
97The functions prefixed \*(``_nc\*('' are normally not available;
98they must be configured into the library
99at build time using the \fB\%\-\-disable-leaks\fP option.
100That compiles-in code that frees memory that normally would not be freed.
101.PP
102The \fB\%exit_curses\fP and \fB\%exit_terminfo\fP functions
103call \fB\%_nc_free_and_exit\fP and \fB\%_nc_free_tinfo\fP if
104the library is configured to support memory-leak checking.
105If the library is not configured to support memory-leak checking,
106they simply call \fBexit\fP.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530107.SH RETURN VALUE
108These functions do not return a value.
109.SH PORTABILITY
micky3879b9f5e72025-07-08 18:04:53 -0400110These functions are not part of X/Open Curses;
111nor do other implementations of curses provide a similar feature.
112.PP
113In any implementation of X/Open Curses, an application can free part
114of the memory allocated by curses:
115.bP
116The portable part of \fB\%exit_curses\fP can be freed using \fB\%delscreen\fP,
117passing the \fISCREEN\fP pointer returned by \fB\%newterm\fP.
118.IP
119In some implementations, there is a global variable \fBsp\fP
120which could be used, e.g., if the screen were only initialized
121using \fB\%initscr\fP.
122.bP
123The portable part of \fB\%exit_terminfo\fP can be freed
124using \fB\%del_curterm\fP.
125.IP
126In this case, there is a global variable \fB\%cur_term\fP which can be
127used as parameter.
Amit Daniel Kachhape6a01f52011-07-20 11:45:59 +0530128.SH SEE ALSO
micky3879b9f5e72025-07-08 18:04:53 -0400129\fB\%curses\fP(3X),
130\fB\%curs_initscr\fP(3X),
131\fB\%curs_terminfo\fP(3X)