我有一个正在编写的程序可以更好地理解ncurses,当我将其推送通过时valgrind,它会输出与ncurses命令相关的许多泄漏。但是,我仅使用stdscr和endwin()在末尾调用main()。我通过使用menu.h设置了用户选项,并在最后使用了free_item和free_menu:
menuChoice(WINDOW* scr, std::vector<std::string> *choices,
std::string desc)
{
//create the menu and the item pointer vector
MENU* my_menu;
std::vector<ITEM*> my_items;
ITEM* cur = NULL;
for (int x = 0; x < choices->size(); x++)
{
//populate the items vector with the string data in choices
my_items.push_back(new_item(choices->at(x).c_str(), NULL));
}
//pushback a null item
my_items.push_back((ITEM*)NULL);
//create the menu and attach the items
my_menu = new_menu((ITEM**)my_items.data());
//print the desc and post the menu
mvwprintw(scr, LINES - …Run Code Online (Sandbox Code Playgroud)