curs_memleaks(3X)
π curs_memleaks β Library calls π
okay bestie, so this whole page is about curs_memleaks(3X) from the ncurses library-calls corner of the world, and it's literally the manual for hunting down memory leaks in curses. yes. we're doing detective work. πβ¨
β¨ NAME β¨
exit_curses, exit_terminfo β check for memory leaks in curses π§π
πΈ SYNOPSIS πΈ
#include <curses.h>
void exit_curses(int code);
#include <term.h>
void exit_terminfo(int code);
/* deprecated (intentionally not declared in curses.h or term.h) */
void _nc_freeall(void);
void _nc_free_and_exit(int code);
void _nc_free_tinfo(int code);
π DESCRIPTION π
so these functions exist to make memory-leak analysis in the ncurses library so much easier. that's the whole job. no cap.
here's the tea: any implementation of curses must not free the memory that's tied to a screen. why? because even after you call endwin(3X), that memory still has to be sitting there ready for the next call to refresh(3X). and on top of that, there are also chunks of memory that get held onto for performance reasons. which means analyzing curses applications for memory leaks is, like, genuinely hard. π
but!! when you're using the specially configured debugging version of the ncurses library, your application can call functions that free those chunks of memory, which simplifies the whole memory-leak-checking process. iconic behavior tbh.
some of these functions have a _nc_ prefix because they are not meant for use in the non-debugging library:
_nc_freeallβ this frees (almost) all of the memory allocated by ncurses. π (almost!! read that word!!)_nc_free_and_exitβ this frees the memory allocated by ncurses (like_nc_freealldoes), and exits the program. it's preferred over_nc_freeallbecause some of that memory may actually be required to keep the application running. simply exiting (with the given exit-code) is safer. π_nc_free_tinfoβ use this one if only the low-level terminfo functions (and the corresponding library) are used. like_nc_free_and_exit, it exits the program after freeing memory. π¦
now, the functions prefixed with _nc are normally not available. they have to be configured into the library at build time using the --disable-leaks option. that option compiles-in code that frees memory that normally would not be freed. periodt.
and finally, the exit_curses and exit_terminfo functions call _nc_free_and_exit and _nc_free_tinfo if the library is configured to support memory-leak checking. if the library is not configured to support memory-leak checking, they simply call exit. that's it. that's the whole vibe check. β¨
π RETURN VALUE π
these functions do not return a value. nothing. nada. they're void girlies. π
π PORTABILITY π
heads up bestie β these functions are not part of X/Open Curses, and no other implementations of curses provide a similar feature. iykyk. π
in any implementation of X/Open Curses, though, an application can free part of the memory allocated by curses:
- the portable part of
exit_cursescan be freed usingdelscreen, passing theSCREENpointer returned bynewterm.- in some implementations, there is a global variable
spwhich could be used, e.g., if the screen were only initialized usinginitscr.
- in some implementations, there is a global variable
- the portable part of
exit_terminfocan be freed usingdel_curterm.- in this case, there is a global variable
cur_termwhich can be used as parameter.
- in this case, there is a global variable
β SEE ALSO β
curses(3X), curs_initscr(3X), curs_terminfo(3X) π
okay that's the whole page, you ate that π«Ά this was ncurses version 6.6, dated 2024-03-16, and it's the curs_memleaks(3X) page signing off. go free your memory and slay π
β¨π
π¦ where this page comes from
- alpine 3.24: ncurses-doc 6.6_p20260516-r0 Β· X11
- arch rolling: ncurses 6.6-2 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- fedora 44: ncurses-devel 6.6-1.fc44 Β· MIT-open-group
- Copyright 2019-2023,2024 Thomas E. Dickey
- Copyright 2008-2010,2017 Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms