memleaks(3NCURSES)
π memleaks β the "where did my memory GO" girlies π
okay bestie, this is the ncurses page about sniffing out memory leaks β it's a library-calls page from the ncurses manual, and we're gonna go through it together, no skips, no cap. β¨
πΈ 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);
literally just copy that, don't freestyle it bestie π«Ά
π DESCRIPTION π
So these functions exist to make memory-leak analysis in the ncurses library way less of a nightmare. That's the whole vibe. π§
Here's the thing β any implementation of curses is not allowed to free the memory tied to a screen, because even after you call endwin(3NCURSES), that memory has to still be there for the next call to refresh(3NCURSES). There are also chunks of memory being held purely for performance reasons. Which makes leak-checking a curses app lowkey impossible normally. π
But!! If you're running the specially configured debugging version of the ncurses library, your app can call functions that free those chunks of memory, which simplifies the whole memory-leak-checking process. slay β¨
Some of these functions have the _nc_ prefix because they are not intended for use in the non-debugging library. Iconic of them, honestly.
_nc_freeallβ frees (almost) all of the memory allocated by ncurses. Note the "(almost)", she's honest about it. π_nc_free_and_exitβ frees the memory allocated by ncurses (just like_nc_freeall), and then 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 being used. Like_nc_free_and_exit, it exits the program after freeing memory. π¦
The functions prefixed _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 which normally would not be freed. π§
And then: exit_curses and exit_terminfo 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 just simply call exit. casual. π
π RETURN VALUE π
These functions do not return a value. nothing, nada, zero, bye π
π PORTABILITY π
Bestie, listen β these functions are not part of X/Open Curses, and other implementations of curses don't provide a similar feature either. Not a thing anywhere else. Periodt. π
But! In any implementation of X/Open Curses, 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's a global variable sp which could be used, e.g., if the screen were only initialized using initscr.
- The portable part of
exit_terminfocan be freed usingdel_curterm.
In this case, there's a global variable cur_term which can be used as parameter.
iykyk π
π SEE ALSO π
ncurses(3NCURSES), initscr(3NCURSES), terminfo(3NCURSES) β go read those next, bestie, they're the whole friend group π«Ά
mwah π that was the memleaks page, 3NCURSES section, from ncurses 6.6, dated 2024-03-16. thank you for coming to my ted talk, go free your memory (responsibly), and remember: it's giving no leaks, only slay β¨ππ¦
π¦ where this page comes from
- ubuntu resolute: ncurses-doc 6.6+20251231-1 Β· MIT/X11
- ubuntu stonking: ncurses-doc 6.6+20260608-2 Β· MIT/X11
- 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