A nota citada no título pode ser encontrada frequentemente na documentação de GTk4
. Minha pergunta é esta: Existe uma maneira técnica de verificar um programa para determinar se todos os dados relevantes foram devidamente liberados. Gostaria de ilustrar isso com um exemplo baseado na pergunta Populating dropdown with strings in GTK4 .
Testei o programa da seguinte forma:
#include"dropdown-glist.h"
// callback function
void cb_test(GtkDropDown *self,GParamSpec *spec, gpointer data)
{
GObject* object = gtk_drop_down_get_selected_item (self);
const char *key = gtk_string_object_get_string(GTK_STRING_OBJECT(object));
gchar *value =g_hash_table_lookup (data, key);
g_print("select: %s %s\n",key,value);
}
void activate (GtkApplication *app, gpointer data)
{
GtkWidget *window;
window =gtk_application_window_new(app);
gtk_widget_set_size_request(window,50,50);
//GHashTable persists after "activate"
GHashTable *hash_table = g_hash_table_new(g_str_hash,g_str_equal);
GtkWidget *drop_down = gtk_drop_down_new(NULL,NULL);
g_hash_table_insert(hash_table,"Key0","value0");
g_hash_table_insert(hash_table,"Key1","value1");
g_hash_table_insert(hash_table,"Key2","value2");
g_hash_table_insert(hash_table,"Key3","value3");
guint hash_size;
/* Get the keys, which are strings, as an array */
gpointer key_array = g_hash_table_get_keys_as_array (hash_table, &hash_size);
/* Create a new GtkStringList model from the array of strings. */
GtkStringList *stringlist = gtk_string_list_new (key_array);
/* Set the model as the source for the dropdown menu. */
gtk_drop_down_set_model (GTK_DROP_DOWN(drop_down), G_LIST_MODEL(stringlist));
// nothing selected
gtk_drop_down_set_selected (GTK_DROP_DOWN (drop_down),GTK_INVALID_LIST_POSITION);
//only here so that changes in the dropdown do not lead to a callback beforehand
g_signal_connect(drop_down, "notify::selected-item", G_CALLBACK(cb_test),hash_table);
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,10);
gtk_box_append(GTK_BOX(box),drop_down);
gtk_window_set_child(GTK_WINDOW(window),box);
gtk_widget_set_visible(window,TRUE);
}
Existe uma maneira técnica de verificar se devo hash_table
ser liberado neste exemplo?
Obrigado pela resposta explicativa.