Hello everyone. Faced a problem:
There are leaks when using the gtk_builder_add_from_file() and gtk_init() function; g_object_unref() does not help in this case.
It starts on macOS Mojave
You cannot really detect leaks like this, with GTK (and its dependent libraries).
First of all, GTK will perform one-off allocations; these are not leaks by definition, as they are performed once, and they will be collected when the process terminates.
Additionally, GTK is using reference counting for most of its data structures; this means that resources will only be collected once their reference count drops to zero. For GtkBuilder, that happens when you explicitly call g_object_unref() once you’re done extracting all the widgets you care about. The ownership of the widgets created by GtkBuilder, though, is transferred to their parent container, and the ownership of the top-level GtkWindow is transferred to GTK itself. This is why calling g_object_unref() on the GtkBuilder instance does not seem to release memory: the resources allocated for each widget are owned by the top level window, and they will be collected when the window is closed.
Additionally, I’d recommend using Valgrind to detect memory leaks and other memory issues; GLib and GTK can integrate with Valgrind and avoid false positives.