title: How to properly manage memory in GTK3?
body: <p>I'm trying to set a small project in C using GTK3.  Coding on linux 64 bits, here is a minimal <em>Hello world</em> program I've set up, inspired from the <a href="https://developer.gnome.org/gtk3/stable/gtk-getting-started.html#gtk-getting-started-hello-world" rel="nofollow">documentation</a> itself.</p>
  
  <pre><code>#include &lt;gtk/gtk.h&gt;
  
  static void
  activate (GtkApplication* app,
            gpointer        user_data)   
  {
      GtkWidget *window;
      GtkWidget *label;
  
      window = gtk_application_window_new( app );
      gtk_window_set_title( GTK_WINDOW( window ), "Minimal GTK" );
      gtk_window_set_default_size( GTK_WINDOW( window ), 400, 300 );
  
      label = gtk_label_new( "Some men just want to watch the world burn." );
      gtk_container_add( GTK_CONTAINER(window), label );
  
      gtk_widget_show_all( window );
  }
  
  
  
  int
  main(int    argc,
       char **argv)
  {
      GtkApplication *app;
      int app_status;
  
      app = gtk_application_new( "com.github.laerne.minimal_gtk", G_APPLICATION_FLAGS_NONE );
      g_signal_connect( app, "activate", G_CALLBACK(activate), NULL );
  
      app_status = g_application_run( G_APPLICATION(app), argc, argv );
      g_object_unref( app );
  
      return app_status;
  }
  </code></pre>
  
  <p>Simple enough.  It works.  However, when running the program with valgrind's memcheck module, valgrind complains about memory leaks :</p>
  
  <pre><code>==11415== LEAK SUMMARY:
  ==11415==    definitely lost: 1,856 bytes in 4 blocks
  ==11415==    indirectly lost: 7,455 bytes in 320 blocks
  ==11415==      possibly lost: 4,899 bytes in 56 blocks
  ==11415==    still reachable: 1,809,562 bytes in 22,030 blocks
  ==11415==                       of which reachable via heuristic:
  ==11415==                         length64           : 6,240 bytes in 102 blocks
  ==11415==                         newarray           : 2,144 bytes in 54 blocks
  ==11415==         suppressed: 0 bytes in 0 blocks
  ==11415== Reachable blocks (those to which a pointer was found) are not shown.
  ==11415== To see them, rerun with: --leak-check=full --show-leak-kinds=all
  ==11415== 
  ==11415== For counts of detected and suppressed errors, rerun with: -v
  ==11415== ERROR SUMMARY: 42 errors from 42 contexts (suppressed: 0 from 0)
  </code></pre>
  
  <p>Running with <code>--leak-check=full</code>, I see that GTK allocate a bunch of memory itself, and I'm lost of what needs to be done.  I though that doing <code>g_object_unref</code> on the <code>GtkApplication</code> was enough to recursively free all widgets of all windows associated with that <code>GtkApplication</code>.  Am I wrong ?  </p>
  
  <p>What should I do to avoid memory leaks ?  Thank you for your help.</p>