GListModel: how to free memory?

In GTK 3, gtk_file_chooser_get_files() returns a GSList. In GTK 4, it returns a GListModel:
https://developer.gnome.org/gtk3/stable/GtkFileChooser.html#gtk-file-chooser-get-files
https://developer.gnome.org/gtk4/stable/GtkFileChooser.html#gtk-file-chooser-get-files
https://developer.gnome.org/glib/stable/glib-Singly-Linked-Lists.html
https://developer.gnome.org/gio/stable/GListModel.html

So in my GTK4 code, I replaced successfully GSList functions by GListModel functions. But why is there no equivalent to g_slist_free() ? How can I free a GListModel ?

The docs say:

a list model containing a GFile for each selected file and subfolder in the current folder. Free the returned list with g_object_unref().

It’s a normal GObject with reference counting, and you can use g_object_ref() and g_object_unref() for memory management.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.