I think if you write your code in a high level language and use high level bindings to GTK you should not have to care much.
In plain C or with low level bindings it is not easy to get it correct, Valgrind may help to find leaks.
I wrote recently some text about this topic, but I am not sure if it is fully correct:
http://ssalewski.de/gtkprogramming.html#_legacy_program_layout
“We may wonder if we have to free widgets when we do not need them any longer. Indeed in C code that can be necessary in some cases. GTK uses reference counting for its objects, that is that each object has a reference counter. In C we can increase that counter to reference an object, that is to ensure that it is kept alive and is not destroyed by GTK. When we do not need that object any more we can decrease the reference counter. If the reference counter drops to zero then GTK destroys the object, that is GTK frees its memory and closes related resources. But often we do not have to really care for that. The reason for that is that GTK uses a special variant of reference counting: When we create a widget with a constructor like gtk_button_new() we get an instance which is market as “floating” indicating that the instance is not already owned by someone. Generally we insert each widget that we create into another widget, like a window or another container widget, and that container widget then takes ownership of its child. When the program terminates and the top level window is destroyed, then all its children are automatically freed. So we have not to care about all that memory management in this case. But there are exceptions to this process, so C programmers sometimes have to carefully check when they have to ref() and unref() resources. Fortunately high level languages like Nim or Python have a garbage collector which frees all objects when appropriate, so we have not to care for this. Nim with gintro supports even the new ARC memory management, which is deterministic and scope based: When a widget or another object goes out of scope it is immediately freed and all related resources are closed or released.”