Index: demos/gtk-demo/appwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/appwindow.c,v
retrieving revision 1.34
diff -u -p -r1.34 appwindow.c
--- demos/gtk-demo/appwindow.c	12 Oct 2005 13:23:10 -0000	1.34
+++ demos/gtk-demo/appwindow.c	19 Jul 2006 22:39:59 -0000
@@ -467,6 +467,7 @@ do_appwindow (GtkWidget *do_widget)
 				  "stock-id", GTK_STOCK_OPEN,
 				  NULL);
       gtk_action_group_add_action (action_group, open_action);
+      g_object_unref (open_action);
       gtk_action_group_add_actions (action_group, 
 				    entries, n_entries, 
 				    window);
@@ -490,6 +491,7 @@ do_appwindow (GtkWidget *do_widget)
       gtk_ui_manager_insert_action_group (merge, action_group, 0);
       gtk_window_add_accel_group (GTK_WINDOW (window), 
 				  gtk_ui_manager_get_accel_group (merge));
+			g_object_unref (action_group);
       
       if (!gtk_ui_manager_add_ui_from_string (merge, ui_info, -1, &error))
 	{
Index: demos/gtk-demo/changedisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/changedisplay.c,v
retrieving revision 1.6
diff -u -p -r1.6 changedisplay.c
--- demos/gtk-demo/changedisplay.c	16 Nov 2004 15:49:17 -0000	1.6
+++ demos/gtk-demo/changedisplay.c	19 Jul 2006 22:40:00 -0000
@@ -300,6 +300,8 @@ display_changed_cb (GtkTreeSelection  *s
   GtkTreeModel *model;
   GtkTreeIter iter;
 
+  if (info->current_display)
+    g_object_unref (info->current_display);
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
     gtk_tree_model_get (model, &iter,
 			DISPLAY_COLUMN_DISPLAY, &info->current_display,
@@ -320,6 +322,8 @@ screen_changed_cb (GtkTreeSelection  *se
   GtkTreeModel *model;
   GtkTreeIter iter;
 
+  if (info->current_screen)
+    g_object_unref (info->current_screen);
   if (gtk_tree_selection_get_selected (selection, &model, &iter))
     gtk_tree_model_get (model, &iter,
 			SCREEN_COLUMN_SCREEN, &info->current_screen,
@@ -562,6 +566,14 @@ destroy_info (ChangeDisplayInfo *info)
   g_slist_free (tmp_list);
 
   g_object_unref (info->size_group);
+  g_object_unref (info->display_model);
+  g_object_unref (info->screen_model);
+
+  if (info->current_display)
+    g_object_unref (info->current_display);
+  if (info->current_screen)
+    g_object_unref (info->current_screen);
+
   g_free (info);
 }
 
Index: demos/gtk-demo/combobox.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/combobox.c,v
retrieving revision 1.1
diff -u -p -r1.1 combobox.c
--- demos/gtk-demo/combobox.c	25 May 2005 06:15:19 -0000	1.1
+++ demos/gtk-demo/combobox.c	19 Jul 2006 22:40:00 -0000
@@ -74,6 +74,7 @@ create_stock_icon_store (void)
 			      PIXBUF_COL, pixbuf,
 			      TEXT_COL, label,
 			      -1);
+	  g_object_unref (pixbuf);
 	  g_free (label);
 	}
       else
Index: demos/gtk-demo/drawingarea.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/drawingarea.c,v
retrieving revision 1.8
diff -u -p -r1.8 drawingarea.c
--- demos/gtk-demo/drawingarea.c	16 Nov 2004 15:49:17 -0000	1.8
+++ demos/gtk-demo/drawingarea.c	19 Jul 2006 22:40:00 -0000
@@ -218,6 +218,16 @@ checkerboard_expose (GtkWidget	    *da,
   return TRUE;
 }
 
+static void
+close_window (void)
+{
+  window = NULL;
+
+  if (pixmap)
+    g_object_unref (pixmap);
+  pixmap = NULL;
+}
+
 GtkWidget *
 do_drawingarea (GtkWidget *do_widget)
 {
@@ -233,7 +243,7 @@ do_drawingarea (GtkWidget *do_widget)
 			     gtk_widget_get_screen (do_widget));
       gtk_window_set_title (GTK_WINDOW (window), "Drawing Area");
 
-      g_signal_connect (window, "destroy", G_CALLBACK (gtk_widget_destroyed), &window);
+      g_signal_connect (window, "destroy", G_CALLBACK (close_window), NULL);
 
       gtk_container_set_border_width (GTK_CONTAINER (window), 8);
 
@@ -309,14 +319,9 @@ do_drawingarea (GtkWidget *do_widget)
     }
 
   if (!GTK_WIDGET_VISIBLE (window))
-    {
       gtk_widget_show_all (window);
-    }
   else
-    {
       gtk_widget_destroy (window);
-      window = NULL;
-    }
 
   return window;
 }
Index: demos/gtk-demo/iconview.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/iconview.c,v
retrieving revision 1.5
diff -u -p -r1.5 iconview.c
--- demos/gtk-demo/iconview.c	12 Jul 2005 16:02:19 -0000	1.5
+++ demos/gtk-demo/iconview.c	19 Jul 2006 22:40:00 -0000
@@ -243,6 +243,18 @@ home_clicked (GtkToolItem *item,
 			    TRUE);
 }
 
+static void close_window(void)
+{
+  gtk_widget_destroy (window);
+  window = NULL;
+
+  g_object_unref (file_pixbuf);
+  file_pixbuf = NULL;
+
+  g_object_unref (folder_pixbuf);
+  folder_pixbuf = NULL;
+}
+
 GtkWidget *
 do_iconview (GtkWidget *do_widget)
 {
@@ -258,7 +270,7 @@ do_iconview (GtkWidget *do_widget)
       gtk_window_set_title (GTK_WINDOW (window), "GtkIconView demo");
 
       g_signal_connect (window, "destroy",
-			G_CALLBACK (gtk_widget_destroyed), &window);
+			G_CALLBACK (close_window), NULL);
 
       error = NULL;
       if (!load_pixbufs (&error))
Index: demos/gtk-demo/main.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/main.c,v
retrieving revision 1.57
diff -u -p -r1.57 main.c
--- demos/gtk-demo/main.c	31 May 2006 04:13:01 -0000	1.57
+++ demos/gtk-demo/main.c	19 Jul 2006 22:40:01 -0000
@@ -786,6 +786,8 @@ create_tree (void)
 
   gtk_widget_grab_focus (tree_view);
 
+   g_object_unref (model);
+
   return box;
 }
 
@@ -842,6 +844,27 @@ setup_default_icon (void)
     }
 }
 
+static void
+_gtk_fini (void)
+{
+  gtk_window_set_default_icon_list (NULL);
+  gtk_icon_factory_remove_default (NULL);
+  gdk_display_close (gdk_display_get_default ());
+
+  do
+    {
+      while (gtk_events_pending ())
+	gtk_main_iteration ();
+
+      gdk_flush ();
+      g_usleep (1000);
+      gdk_flush ();
+    }
+  while (gtk_events_pending ());
+
+  g_main_context_unref (g_main_context_default ());
+}
+
 int
 main (int argc, char **argv)
 {
@@ -869,7 +892,7 @@ main (int argc, char **argv)
   
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "GTK+ Code Demos");
-  g_signal_connect (window, "destroy",
+  g_signal_connect_after (window, "destroy",
 		    G_CALLBACK (gtk_main_quit), NULL);
 
   hbox = gtk_hbox_new (FALSE, 0);
@@ -885,13 +908,15 @@ main (int argc, char **argv)
 			    create_text (&info_buffer, FALSE),
 			    gtk_label_new_with_mnemonic ("_Info"));
 
+  tag = gtk_text_buffer_create_tag (info_buffer, "title",
+                                    "font", "Sans 18",
+                                    NULL);
+   g_object_unref (info_buffer);
+
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
 			    create_text (&source_buffer, TRUE),
 			    gtk_label_new_with_mnemonic ("_Source"));
 
-  tag = gtk_text_buffer_create_tag (info_buffer, "title",
-                                    "font", "Sans 18",
-                                    NULL);
 
   tag = gtk_text_buffer_create_tag (source_buffer, "comment",
 				    "foreground", "DodgerBlue",
@@ -914,6 +939,7 @@ main (int argc, char **argv)
 				    "weight", PANGO_WEIGHT_BOLD,
  				    "foreground", "DarkGoldenrod4",
                                     NULL);
+   g_object_unref (source_buffer);
   
   gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
   gtk_widget_show_all (window);
@@ -922,6 +948,8 @@ main (int argc, char **argv)
   load_file (testgtk_demos[0].filename);
   
   gtk_main ();
+
+  _gtk_fini ();
 
   return 0;
 }
Index: demos/gtk-demo/ui_manager.c
===================================================================
RCS file: /cvs/gnome/gtk+/demos/gtk-demo/ui_manager.c,v
retrieving revision 1.6
diff -u -p -r1.6 ui_manager.c
--- demos/gtk-demo/ui_manager.c	16 Nov 2004 15:49:17 -0000	1.6
+++ demos/gtk-demo/ui_manager.c	19 Jul 2006 22:40:01 -0000
@@ -183,10 +183,12 @@ do_ui_manager (GtkWidget *do_widget)
 
       ui = gtk_ui_manager_new ();
       gtk_ui_manager_insert_action_group (ui, actions, 0);
+      g_object_unref (actions);
       gtk_window_add_accel_group (GTK_WINDOW (window), 
 				  gtk_ui_manager_get_accel_group (ui));
       gtk_window_set_title (GTK_WINDOW (window), "UI Manager");
       gtk_container_set_border_width (GTK_CONTAINER (window), 0);
+
       
       if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error))
 	{
@@ -223,6 +225,7 @@ do_ui_manager (GtkWidget *do_widget)
       gtk_widget_grab_default (button);
 
       gtk_widget_show_all (window);
+      g_object_unref (ui);
     }
   else
     {
Index: gdk/gdkevents.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkevents.c,v
retrieving revision 1.76
diff -u -p -r1.76 gdkevents.c
--- gdk/gdkevents.c	6 Dec 2005 10:40:09 -0000	1.76
+++ gdk/gdkevents.c	19 Jul 2006 22:40:04 -0000
@@ -363,7 +363,7 @@ gdk_event_copy (GdkEvent *event)
 
   *new_event = *event;
   if (new_event->any.window)
-    g_object_ref (new_event->any.window);
+    g_object_ref_and_context (new_event->any.window);
 
   if (gdk_event_is_allocated (event))
     {
@@ -372,17 +372,17 @@ gdk_event_copy (GdkEvent *event)
       new_private->screen = private->screen;
     }
   
-  switch (event->any.type)
+  switch (new_event->any.type)
     {
     case GDK_KEY_PRESS:
     case GDK_KEY_RELEASE:
-      new_event->key.string = g_strdup (event->key.string);
+      new_event->key.string = g_strdup (new_event->key.string);
       break;
       
     case GDK_ENTER_NOTIFY:
     case GDK_LEAVE_NOTIFY:
-      if (event->crossing.subwindow != NULL)
-	g_object_ref (event->crossing.subwindow);
+      if (new_event->crossing.subwindow != NULL)
+	g_object_ref_and_context (new_event->crossing.subwindow);
       break;
       
     case GDK_DRAG_ENTER:
@@ -391,7 +391,7 @@ gdk_event_copy (GdkEvent *event)
     case GDK_DRAG_STATUS:
     case GDK_DROP_START:
     case GDK_DROP_FINISHED:
-      g_object_ref (event->dnd.context);
+      g_object_ref_and_context (new_event->dnd.context);
       break;
       
     case GDK_EXPOSE:
@@ -439,7 +439,7 @@ gdk_event_free (GdkEvent *event)
   g_return_if_fail (event != NULL);
 
   if (event->any.window)
-    g_object_unref (event->any.window);
+    g_object_unref_and_context (event->any.window);
   
   switch (event->any.type)
     {
@@ -451,7 +451,7 @@ gdk_event_free (GdkEvent *event)
     case GDK_ENTER_NOTIFY:
     case GDK_LEAVE_NOTIFY:
       if (event->crossing.subwindow != NULL)
-	g_object_unref (event->crossing.subwindow);
+	g_object_unref_and_context (event->crossing.subwindow);
       break;
       
     case GDK_DRAG_ENTER:
@@ -460,7 +460,7 @@ gdk_event_free (GdkEvent *event)
     case GDK_DRAG_STATUS:
     case GDK_DROP_START:
     case GDK_DROP_FINISHED:
-      g_object_unref (event->dnd.context);
+      g_object_unref_and_context (event->dnd.context);
       break;
 
     case GDK_BUTTON_PRESS:
Index: gdk/gdkgc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkgc.c,v
retrieving revision 1.54
diff -u -p -r1.54 gdkgc.c
--- gdk/gdkgc.c	14 May 2006 03:58:05 -0000	1.54
+++ gdk/gdkgc.c	19 Jul 2006 22:40:05 -0000
@@ -160,13 +160,13 @@ _gdk_gc_init (GdkGC           *gc,
     {
       priv->stipple = values->stipple;
       if (priv->stipple)
-	g_object_ref (priv->stipple);
+	g_object_ref_and_context (priv->stipple);
     }
   if (values_mask & GDK_GC_TILE)
     {
       priv->tile = values->tile;
       if (priv->tile)
-	g_object_ref (priv->tile);
+	g_object_ref_and_context (priv->tile);
     }
   if (values_mask & GDK_GC_FOREGROUND)
     priv->fg_pixel = values->foreground.pixel;
@@ -175,7 +175,7 @@ _gdk_gc_init (GdkGC           *gc,
 
   gc->colormap = gdk_drawable_get_colormap (drawable);
   if (gc->colormap)
-    g_object_ref (gc->colormap);
+    g_object_ref_and_context (gc->colormap);
 }
 
 static void
@@ -187,11 +187,11 @@ gdk_gc_finalize (GObject *object)
   if (priv->clip_region)
     gdk_region_destroy (priv->clip_region);
   if (gc->colormap)
-    g_object_unref (gc->colormap);
+    g_object_unref_and_context (gc->colormap);
   if (priv->tile)
-    g_object_unref (priv->tile);
+    g_object_unref_and_context (priv->tile);
   if (priv->stipple)
-    g_object_unref (priv->stipple);
+    g_object_unref_and_context (priv->stipple);
 
   G_OBJECT_CLASS (gdk_gc_parent_class)->finalize (object);
 }
@@ -293,10 +293,10 @@ gdk_gc_set_values (GdkGC           *gc,
       if (priv->stipple != values->stipple)
 	{
 	  if (priv->stipple)
-	    g_object_unref (priv->stipple);
+	    g_object_unref_and_context (priv->stipple);
 	  priv->stipple = values->stipple;
 	  if (priv->stipple)
-	    g_object_ref (priv->stipple);
+	    g_object_ref_and_context (priv->stipple);
 	}
     }
   if (values_mask & GDK_GC_TILE)
@@ -304,10 +304,10 @@ gdk_gc_set_values (GdkGC           *gc,
       if (priv->tile != values->tile)
 	{
 	  if (priv->tile)
-	    g_object_unref (priv->tile);
+	    g_object_unref_and_context (priv->tile);
 	  priv->tile = values->tile;
 	  if (priv->tile)
-	    g_object_ref (priv->tile);
+	    g_object_ref_and_context (priv->tile);
 	}
     }
   if (values_mask & GDK_GC_FOREGROUND)
@@ -873,10 +873,10 @@ gdk_gc_copy (GdkGC *dst_gc,
   dst_gc->ts_y_origin = src_gc->ts_y_origin;
 
   if (src_gc->colormap)
-    g_object_ref (src_gc->colormap);
+    g_object_ref_with_context (src_gc->colormap, &dst_gc->colormap);
 
   if (dst_gc->colormap)
-    g_object_unref (dst_gc->colormap);
+    g_object_unref_and_context (dst_gc->colormap);
 
   dst_gc->colormap = src_gc->colormap;
 
@@ -891,16 +891,16 @@ gdk_gc_copy (GdkGC *dst_gc,
   dst_priv->fill = src_priv->fill;
   
   if (dst_priv->stipple)
-    g_object_unref (dst_priv->stipple);
+    g_object_unref_and_context (dst_priv->stipple);
   dst_priv->stipple = src_priv->stipple;
   if (dst_priv->stipple)
-    g_object_ref (dst_priv->stipple);
+    g_object_ref_and_context (dst_priv->stipple);
   
   if (dst_priv->tile)
-    g_object_unref (dst_priv->tile);
+    g_object_unref_and_context (dst_priv->tile);
   dst_priv->tile = src_priv->tile;
   if (dst_priv->tile)
-    g_object_ref (dst_priv->tile);
+    g_object_ref_and_context (dst_priv->tile);
 
   dst_priv->fg_pixel = src_priv->fg_pixel;
   dst_priv->bg_pixel = src_priv->bg_pixel;
@@ -925,10 +925,10 @@ gdk_gc_set_colormap (GdkGC       *gc,
   if (gc->colormap != colormap)
     {
       if (gc->colormap)
-	g_object_unref (gc->colormap);
+	g_object_unref_and_context (gc->colormap);
 
       gc->colormap = colormap;
-      g_object_ref (gc->colormap);
+      g_object_ref_and_context (gc->colormap);
     }
     
 }
Index: gdk/gdkimage.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkimage.c,v
retrieving revision 1.38
diff -u -p -r1.38 gdkimage.c
--- gdk/gdkimage.c	12 Jan 2006 13:50:51 -0000	1.38
+++ gdk/gdkimage.c	19 Jul 2006 22:40:05 -0000
@@ -115,10 +115,10 @@ gdk_image_set_colormap (GdkImage       *
   if (image->colormap != colormap)
     {
       if (image->colormap)
-	g_object_unref (image->colormap);
+	g_object_unref_and_context (image->colormap);
 
       image->colormap = colormap;
-      g_object_ref (image->colormap);
+      g_object_ref_and_context (image->colormap);
     }
     
 }
Index: gdk/gdkpango.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkpango.c,v
retrieving revision 1.57
diff -u -p -r1.57 gdkpango.c
--- gdk/gdkpango.c	8 Jul 2006 22:58:06 -0000	1.57
+++ gdk/gdkpango.c	19 Jul 2006 22:40:07 -0000
@@ -576,15 +576,15 @@ gdk_pango_renderer_new (GdkScreen *scree
 }
 
 static void
-on_renderer_display_closed (GdkDisplay       *display,
-                            gboolean          is_error,
-			    GdkPangoRenderer *renderer)
-{
-  g_signal_handlers_disconnect_by_func (display,
-					on_renderer_display_closed,
-					renderer);
-  g_object_set_data (G_OBJECT (renderer->priv->screen),
-                     g_intern_static_string ("gdk-pango-renderer"), NULL);
+on_renderer_screen_closed (GdkScreen       *screen, GdkPangoRenderer *renderer)
+{
+  g_signal_handlers_disconnect_by_func (screen,
+					on_renderer_screen_closed,
+					NULL);
+  g_object_set_data (G_OBJECT (screen),
+      g_intern_static_string ("gdk-pango-renderer"), NULL);
+
+  g_object_unref_with_context (renderer, renderer);
 }
 
 /**
@@ -617,12 +617,11 @@ gdk_pango_renderer_get_default (GdkScree
   if (!renderer)
     {
       renderer = gdk_pango_renderer_new (screen);
-      g_object_set_data_full (G_OBJECT (screen), 
-                              g_intern_static_string ("gdk-pango-renderer"), renderer,
-			      (GDestroyNotify)g_object_unref);
+      g_object_set_data (G_OBJECT (screen),
+                              g_intern_static_string ("gdk-pango-renderer"), renderer);
 
-      g_signal_connect (gdk_screen_get_display (screen), "closed",
-			G_CALLBACK (on_renderer_display_closed), renderer);
+      g_signal_connect ( screen, "closed",
+			G_CALLBACK (on_renderer_screen_closed), renderer);
     }
 
   return renderer;
@@ -651,10 +650,10 @@ gdk_pango_renderer_set_drawable (GdkPang
   if (priv->drawable != drawable)
     {
       if (priv->drawable)
-	g_object_unref (priv->drawable);
+	g_object_unref_and_context (priv->drawable);
       priv->drawable = drawable;
       if (priv->drawable)
-	g_object_ref (priv->drawable);
+	g_object_ref_and_context (priv->drawable);
     }
 }
 
@@ -685,10 +684,10 @@ gdk_pango_renderer_set_gc (GdkPangoRende
   if (priv->base_gc != gc)
     {
       if (priv->base_gc)
-	g_object_unref (priv->base_gc);
+	g_object_unref_and_context (priv->base_gc);
       priv->base_gc = gc;
       if (priv->base_gc)
-	g_object_ref (priv->base_gc);
+	g_object_ref_and_context (priv->base_gc);
 
       priv->gc_changed = TRUE;
     }
@@ -723,12 +722,12 @@ gdk_pango_renderer_set_stipple (GdkPango
   if (stipple != gdk_renderer->priv->stipple[part])
     {
       if (gdk_renderer->priv->stipple[part])
-	g_object_unref (gdk_renderer->priv->stipple[part]);
+	g_object_unref_and_context (gdk_renderer->priv->stipple[part]);
 
       gdk_renderer->priv->stipple[part] = stipple;
       
       if (gdk_renderer->priv->stipple[part])
-	g_object_ref (gdk_renderer->priv->stipple[part]);
+	g_object_ref_and_context (gdk_renderer->priv->stipple[part]);
 
       pango_renderer_part_changed (PANGO_RENDERER (gdk_renderer), part);
     }
@@ -1151,7 +1150,7 @@ gdk_pango_attr_stipple_new (GdkBitmap *s
   result->attr.klass = &klass;
 
   if (stipple)
-    g_object_ref (stipple);
+    g_object_ref_and_context (stipple);
   
   result->stipple = stipple;
 
Index: gdk/gdkrgb.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkrgb.c,v
retrieving revision 1.66
diff -u -p -r1.66 gdkrgb.c
--- gdk/gdkrgb.c	4 Apr 2006 04:07:54 -0000	1.66
+++ gdk/gdkrgb.c	19 Jul 2006 22:40:17 -0000
@@ -533,7 +533,7 @@ gdk_rgb_free_info (GdkRgbInfo *image_inf
     gdk_rgb_cmap_free (image_info->gray_cmap);
 
   if (image_info->own_gc)
-    g_object_unref (image_info->own_gc);
+    g_object_unref_and_context (image_info->own_gc);
 
   if (image_info->colorcube)
     g_free (image_info->colorcube);
@@ -607,7 +607,7 @@ gdk_rgb_create_info (GdkVisual *visual, 
        image_info->visual->depth >= 3))
     {
       if (!image_info->cmap)
-	image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
+	image_info->cmap = g_object_ref_with_context (gdk_screen_get_system_colormap (screen), &image_info->cmap);
       
       gdk_rgb_colorcube_222 (image_info);
     }
@@ -633,7 +633,7 @@ gdk_rgb_create_info (GdkVisual *visual, 
 		 image_info->nblue_shades);
 
       if (!image_info->cmap)
-	image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
+	image_info->cmap = g_object_ref_with_context (gdk_screen_get_system_colormap (screen), &image_info->cmap);
     }
 #ifdef ENABLE_GRAYSCALE
   else if (image_info->visual->type == GDK_VISUAL_GRAYSCALE)
@@ -654,7 +654,7 @@ gdk_rgb_create_info (GdkVisual *visual, 
 	  /* Always install colormap in direct color. */
 	  if (image_info->visual->type != GDK_VISUAL_DIRECT_COLOR &&
 	      image_info->visual == gdk_screen_get_system_visual (screen))
-	    image_info->cmap = g_object_ref (gdk_screen_get_system_colormap (screen));
+	    image_info->cmap = g_object_ref_with_context (gdk_screen_get_system_colormap (screen), &image_info->cmap);
 	  else
 	    {
 	      image_info->cmap = gdk_colormap_new (image_info->visual, FALSE);
Index: gdk/gdkscreen.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkscreen.c,v
retrieving revision 1.30
diff -u -p -r1.30 gdkscreen.c
--- gdk/gdkscreen.c	22 May 2006 17:08:13 -0000	1.30
+++ gdk/gdkscreen.c	19 Jul 2006 22:40:17 -0000
@@ -51,9 +51,11 @@ enum
 {
   SIZE_CHANGED,
   COMPOSITED_CHANGED,
+  CLOSED,
   LAST_SIGNAL
 };
 
+
 static guint signals[LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (GdkScreen, gdk_screen, G_TYPE_OBJECT)
@@ -124,6 +126,25 @@ gdk_screen_class_init (GdkScreenClass *k
 		  g_cclosure_marshal_VOID__VOID,
 		  G_TYPE_NONE,
 		  0);
+
+  /**
+   * GdkScreen::closed:
+   * @screen: the object on which the signal is emitted
+   *
+   * The ::closed signal is emitted when the connection to the windowing
+   * system for @screen is closed.
+   *
+   * Since: 2.12
+   */   
+  signals[CLOSED] =
+    g_signal_new (g_intern_static_string ("closed"),
+		  G_OBJECT_CLASS_TYPE (object_class),
+		  G_SIGNAL_RUN_LAST,
+		  G_STRUCT_OFFSET (GdkScreenClass, closed),
+		  NULL, NULL,
+		  g_cclosure_marshal_VOID__VOID,
+		  G_TYPE_NONE,
+		  0);
 }
 
 static void
@@ -175,6 +196,7 @@ _gdk_screen_close (GdkScreen *screen)
   if (!screen->closed)
     {
       screen->closed = TRUE;
+      g_signal_emit (screen, signals[CLOSED], 0);
       g_object_run_dispose (G_OBJECT (screen));
     }
 }
Index: gdk/gdkscreen.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkscreen.h,v
retrieving revision 1.19
diff -u -p -r1.19 gdkscreen.h
--- gdk/gdkscreen.h	25 Apr 2006 14:27:28 -0000	1.19
+++ gdk/gdkscreen.h	19 Jul 2006 22:40:17 -0000
@@ -58,6 +58,7 @@ struct _GdkScreenClass
 
   void (*size_changed) (GdkScreen *screen);
   void (*composited_changed) (GdkScreen *screen);
+  void (*closed) (GdkScreen *screen);
 };
 
 GType        gdk_screen_get_type              (void) G_GNUC_CONST;
Index: gdk/gdkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.c,v
retrieving revision 1.187
diff -u -p -r1.187 gdkwindow.c
--- gdk/gdkwindow.c	17 Jul 2006 04:19:59 -0000	1.187
+++ gdk/gdkwindow.c	19 Jul 2006 22:40:20 -0000
@@ -305,7 +305,7 @@ gdk_window_finalize (GObject *object)
 	_gdk_window_destroy (window, TRUE);
     }
 
-  g_object_unref (obj->impl);
+  g_object_unref_with_context (obj->impl, obj->impl);
   obj->impl = NULL;
   
   G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -485,7 +485,7 @@ void
 gdk_window_destroy (GdkWindow *window)
 {
   _gdk_window_destroy_hierarchy (window, FALSE, FALSE);
-  g_object_unref (window);
+  g_object_unref_with_context (window, window);
 }
 
 /**
@@ -2315,7 +2315,7 @@ gdk_window_process_updates_internal (Gdk
 	      GdkEvent event;
 	      
 	      event.expose.type = GDK_EXPOSE;
-	      event.expose.window = g_object_ref (window);
+	      event.expose.window = g_object_ref_with_context (window, &event.expose.window);
 	      event.expose.send_event = FALSE;
 	      event.expose.count = 0;
 	      event.expose.region = expose_region;
@@ -2323,7 +2323,7 @@ gdk_window_process_updates_internal (Gdk
 	      
 	      (*_gdk_event_func) (&event, _gdk_event_data);
 	      
-	      g_object_unref (window);
+	      g_object_unref_with_context (window, &event.expose.window);
 	    }
 
 	  if (expose_region != update_area)
@@ -2375,18 +2375,16 @@ gdk_window_process_all_updates (void)
   update_windows = NULL;
   update_idle = 0;
 
-  g_slist_foreach (old_update_windows, (GFunc)g_object_ref, NULL);
-  
   while (tmp_list)
     {
-      GdkWindowObject *private = (GdkWindowObject *)tmp_list->data;
+      GdkWindowObject *private = g_object_ref_and_context (tmp_list->data);
       
       if (private->update_freeze_count)
 	update_windows = g_slist_prepend (update_windows, private);
       else
 	gdk_window_process_updates_internal (tmp_list->data);
       
-      g_object_unref (tmp_list->data);
+      g_object_unref_and_context (tmp_list->data);
       tmp_list = tmp_list->next;
     }
 
Index: gdk/win32/gdkdnd-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkdnd-win32.c,v
retrieving revision 1.45
diff -u -p -r1.45 gdkdnd-win32.c
--- gdk/win32/gdkdnd-win32.c	17 Jun 2005 19:41:01 -0000	1.45
+++ gdk/win32/gdkdnd-win32.c	19 Jul 2006 22:40:22 -0000
@@ -172,11 +172,11 @@ gdk_drag_context_finalize (GObject *obje
 
   if (context->source_window)
     {
-      g_object_unref (context->source_window);
+      g_object_unref_and_context (context->source_window);
     }
   
   if (context->dest_window)
-    g_object_unref (context->dest_window);
+    g_object_unref_and_context (context->dest_window);
   
   contexts = g_list_remove (contexts, context);
 
@@ -972,9 +972,9 @@ gdk_dropfiles_filter (GdkXEvent *xev,
       context->protocol = GDK_DRAG_PROTO_WIN32_DROPFILES;
       context->is_source = FALSE;
       context->source_window = _gdk_root;
-      g_object_ref (context->source_window);
+      g_object_ref_and_context (context->source_window);
       context->dest_window = event->any.window;
-      g_object_ref (context->dest_window);
+      g_object_ref_and_context (context->dest_window);
       /* WM_DROPFILES drops are always file names */
       context->targets =
 	g_list_append (NULL, GUINT_TO_POINTER (_text_uri_list));
@@ -1137,9 +1137,9 @@ local_send_enter (GdkDragContext *contex
   new_context->is_source = FALSE;
 
   new_context->source_window = context->source_window;
-  g_object_ref (new_context->source_window);
+  g_object_ref_and_context (new_context->source_window);
   new_context->dest_window = context->dest_window;
-  g_object_ref (new_context->dest_window);
+  g_object_ref_and_context (new_context->dest_window);
 
   new_context->targets = g_list_copy (context->targets);
 
@@ -1240,7 +1240,7 @@ gdk_drag_do_leave (GdkDragContext *conte
 	  break;
 	}
 
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
 }
@@ -1258,7 +1258,7 @@ gdk_drag_begin (GdkWindow *window,
   new_context = gdk_drag_context_new ();
   new_context->is_source = TRUE;
   new_context->source_window = window;
-  g_object_ref (window);
+  g_object_ref_and_context (new_context->source_window);
 
   tmp_list = g_list_last (targets);
   new_context->targets = NULL;
@@ -1288,7 +1288,7 @@ gdk_drag_begin (GdkWindow *window,
   ctx = source_context_new ();
   ctx->context->protocol = GDK_DRAG_PROTO_OLE2;
   ctx->context->source_window = window;
-  g_object_ref (window);
+  g_object_ref_and_context (ctx->context->source_window);
 
   tmp_list = g_list_last (targets);
   ctx->context->targets = NULL;
@@ -1459,7 +1459,7 @@ gdk_drag_motion (GdkDragContext *context
       if (dest_window)
 	{
 	  context->dest_window = dest_window;
-	  g_object_ref (context->dest_window);
+	  g_object_ref_and_context (context->dest_window);
 	  context->protocol = protocol;
 
 	  switch (protocol)
Index: gdk/win32/gdkevents-win32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/win32/gdkevents-win32.c,v
retrieving revision 1.167
diff -u -p -r1.167 gdkevents-win32.c
--- gdk/win32/gdkevents-win32.c	8 Jun 2006 15:00:25 -0000	1.167
+++ gdk/win32/gdkevents-win32.c	19 Jul 2006 22:40:25 -0000
@@ -1201,11 +1201,11 @@ static void
 fixup_event (GdkEvent *event)
 {
   if (event->any.window)
-    g_object_ref (event->any.window);
+    g_object_ref_and_context (event->any.window);
   if (((event->any.type == GDK_ENTER_NOTIFY) ||
        (event->any.type == GDK_LEAVE_NOTIFY)) &&
       (event->crossing.subwindow != NULL))
-    g_object_ref (event->crossing.subwindow);
+    g_object_ref_and_context (event->crossing.subwindow);
   event->any.send_event = InSendMessage (); 
 }
 
@@ -1296,7 +1296,7 @@ apply_filters (GdkWindow  *window,
 
   event = gdk_event_new (GDK_NOTHING);
   if (window != NULL)
-    event->any.window = g_object_ref (window);
+    event->any.window = g_object_ref_with_context (window, &event->any.window);
   ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
 
   /* I think GdkFilterFunc semantics require the passed-in event
@@ -3547,7 +3547,7 @@ gdk_event_translate (MSG  *msg,
 
       event = gdk_event_new (GDK_NOTHING);
       event->any.window = window;
-      g_object_ref (window);
+      g_object_ref_and_context (event->any.window);
       if (_gdk_input_other_event (event, msg, window))
 	append_event (event);
       else
Index: gdk/x11/gdkcolor-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkcolor-x11.c,v
retrieving revision 1.65
diff -u -p -r1.65 gdkcolor-x11.c
--- gdk/x11/gdkcolor-x11.c	14 May 2006 03:58:06 -0000	1.65
+++ gdk/x11/gdkcolor-x11.c	19 Jul 2006 22:40:26 -0000
@@ -404,6 +404,7 @@ gdk_screen_get_system_colormap (GdkScree
   
   gdk_colormap_add (colormap);
   screen_x11->system_colormap = colormap;
+  g_object_ref_set_context (colormap, colormap, &screen_x11->system_colormap);
   
   return colormap;
 }
Index: gdk/x11/gdkdisplay-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdisplay-x11.c,v
retrieving revision 1.74
diff -u -p -r1.74 gdkdisplay-x11.c
--- gdk/x11/gdkdisplay-x11.c	28 Jun 2006 12:44:30 -0000	1.74
+++ gdk/x11/gdkdisplay-x11.c	19 Jul 2006 22:40:27 -0000
@@ -738,8 +738,41 @@ gdk_display_x11_dispose (GObject *object
   GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
   gint           i;
 
+   if (display_x11->leader_gdk_window)
+     {
+       _gdk_window_destroy (display_x11->leader_gdk_window, TRUE);
+       gdk_window_destroy_notify (display_x11->leader_gdk_window);
+       g_object_unref_with_context (display_x11->leader_gdk_window, display_x11->leader_gdk_window);
+       display_x11->leader_gdk_window = NULL;
+     }
+
   for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
-    _gdk_screen_close (display_x11->screens[i]);
+    {
+      if (display_x11->screens[i])
+	{
+	  _gdk_screen_close (display_x11->screens[i]);
+	  g_object_unref_with_context (display_x11->screens[i],
+	      display_x11->screens[i]);
+	  display_x11->screens[i] = NULL;
+	}
+    }
+
+  /* input GdkDevice list */
+  if (display_x11->input_devices)
+    {
+      /* FIXME need to write finalize fct */
+      g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
+      g_list_free (display_x11->input_devices);
+      display_x11->input_devices = NULL;
+    }
+
+  /* input GdkWindow list */
+  if (display_x11->input_windows)
+    {
+      g_list_foreach (display_x11->input_windows, (GFunc) g_object_unref, NULL);
+      g_list_free (display_x11->input_windows);
+      display_x11->input_windows = NULL;
+    }
 
   _gdk_events_uninit (GDK_DISPLAY_OBJECT (object));
 
@@ -779,18 +812,6 @@ gdk_display_x11_finalize (GObject *objec
   g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
   g_slist_free (display_x11->event_types);
 
-  /* input GdkDevice list */
-  /* FIXME need to write finalize fct */
-  g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
-  g_list_free (display_x11->input_devices);
-
-  /* input GdkWindow list */
-  g_list_foreach (display_x11->input_windows, (GFunc) g_object_unref, NULL);
-  g_list_free (display_x11->input_windows);
-
-  /* Free all GdkScreens */
-  for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
-    g_object_unref (display_x11->screens[i]);
   g_free (display_x11->screens);
 
   g_free (display_x11->startup_notification_id);
Index: gdk/x11/gdkdnd-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdnd-x11.c,v
retrieving revision 1.92
diff -u -p -r1.92 gdkdnd-x11.c
--- gdk/x11/gdkdnd-x11.c	25 May 2006 05:30:13 -0000	1.92
+++ gdk/x11/gdkdnd-x11.c	19 Jul 2006 22:40:31 -0000
@@ -183,11 +183,11 @@ gdk_drag_context_finalize (GObject *obje
           !context->is_source)
         xdnd_manage_source_filter (context, context->source_window, FALSE);
       
-      g_object_unref (context->source_window);
+      g_object_unref_and_context (context->source_window);
     }
   
   if (context->dest_window)
-    g_object_unref (context->dest_window);
+    g_object_unref_and_context (context->dest_window);
 
   for (tmp_list = private->window_caches; tmp_list; tmp_list = tmp_list->next)
     gdk_window_cache_destroy (tmp_list->data);
@@ -1533,7 +1533,7 @@ motif_drag_context_new (GdkWindow *dest_
     {
       if (timestamp >= display_x11->current_dest_drag->start_time)
 	{
-	  g_object_unref (display_x11->current_dest_drag);
+	  g_object_unref_and_context (display_x11->current_dest_drag);
 	  display_x11->current_dest_drag = NULL;
 	}
       else
@@ -1548,7 +1548,7 @@ motif_drag_context_new (GdkWindow *dest_
 
   new_context->source_window = gdk_window_lookup_for_display (display, source_window);
   if (new_context->source_window)
-    g_object_ref (new_context->source_window);
+    g_object_ref_and_context (new_context->source_window);
   else
     {
       new_context->source_window = gdk_window_foreign_new_for_display (display, source_window);
@@ -1560,7 +1560,7 @@ motif_drag_context_new (GdkWindow *dest_
     }
 
   new_context->dest_window = dest_window;
-  g_object_ref (dest_window);
+  g_object_ref_and_context (new_context->dest_window);
   new_context->start_time = timestamp;
 
   if (!motif_read_initiator_info (GDK_WINDOW_DISPLAY (dest_window),
@@ -1602,7 +1602,7 @@ motif_top_level_enter (GdkEvent *event,
 
   event->dnd.type = GDK_DRAG_ENTER;
   event->dnd.context = new_context;
-  g_object_ref (new_context);
+  g_object_ref_and_context (event->dnd.context);
 
   display_x11->current_dest_drag = new_context;
 
@@ -1656,7 +1656,7 @@ motif_motion (GdkEvent *event,
 
       event->dnd.type = GDK_DRAG_MOTION;
       event->dnd.context = display_x11->current_dest_drag;
-      g_object_ref (display_x11->current_dest_drag);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = timestamp;
 
@@ -1693,7 +1693,7 @@ motif_operation_changed (GdkEvent *event
       event->dnd.type = GDK_DRAG_MOTION;
       event->dnd.send_event = FALSE;
       event->dnd.context = display_x11->current_dest_drag;
-      g_object_ref (display_x11->current_dest_drag);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = timestamp;
       private = PRIVATE_DATA (display_x11->current_dest_drag);
@@ -1740,7 +1740,7 @@ motif_drop_start (GdkEvent *event,
 
   gdk_x11_window_set_user_time (event->any.window, timestamp);
 
-  g_object_ref (new_context);
+  g_object_ref_and_context (event->dnd.context);
   display_x11->current_dest_drag = new_context;
 
   return GDK_FILTER_TRANSLATE;
@@ -1773,7 +1773,7 @@ motif_drag_status (GdkEvent *event,
       event->dnd.type = GDK_DRAG_STATUS;
       event->dnd.send_event = FALSE;
       event->dnd.context = context;
-      g_object_ref (context);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = timestamp;
 
@@ -1982,7 +1982,7 @@ xdnd_status_filter (GdkXEvent *xev,
       event->dnd.send_event = FALSE;
       event->dnd.type = GDK_DRAG_STATUS;
       event->dnd.context = context;
-      g_object_ref (context);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
       if (!(action != 0) != !(flags & 1))
@@ -2029,7 +2029,7 @@ xdnd_finished_filter (GdkXEvent *xev,
       
       event->dnd.type = GDK_DROP_FINISHED;
       event->dnd.context = context;
-      g_object_ref (context);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
 
@@ -2214,7 +2214,7 @@ xdnd_send_xevent (GdkDragContext *contex
 	      if  ((*xdnd_filters[i].func) (event_send, &temp_event, NULL) == GDK_FILTER_TRANSLATE)
 		{
 		  gdk_event_put (&temp_event);
-		  g_object_unref (temp_event.dnd.context);
+		  g_object_unref_and_context (temp_event.dnd.context);
 		}
 	      
 	      return TRUE;
@@ -2283,7 +2283,7 @@ xdnd_send_enter (GdkDragContext *context
       GDK_NOTE (DND, 
 		g_message ("Send event to %lx failed",
 			   GDK_DRAWABLE_XID (context->dest_window)));
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
 }
@@ -2314,7 +2314,7 @@ xdnd_send_leave (GdkDragContext *context
       GDK_NOTE (DND, 
 		g_message ("Send event to %lx failed",
 			   GDK_DRAWABLE_XID (context->dest_window)));
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
 }
@@ -2344,7 +2344,7 @@ xdnd_send_drop (GdkDragContext *context,
       GDK_NOTE (DND, 
 		g_message ("Send event to %lx failed",
 			   GDK_DRAWABLE_XID (context->dest_window)));
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
 }
@@ -2378,7 +2378,7 @@ xdnd_send_motion (GdkDragContext *contex
       GDK_NOTE (DND, 
 		g_message ("Send event to %lx failed",
 			   GDK_DRAWABLE_XID (context->dest_window)));
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
   private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
@@ -2707,7 +2707,7 @@ xdnd_enter_filter (GdkXEvent *xev,
 
   new_context->source_window = gdk_window_lookup_for_display (display, source_window);
   if (new_context->source_window)
-    g_object_ref (new_context->source_window);
+    g_object_ref_and_context (new_context->source_window);
   else
     {
       new_context->source_window = gdk_window_foreign_new_for_display (display, source_window);
@@ -2718,7 +2718,7 @@ xdnd_enter_filter (GdkXEvent *xev,
 	}
     }
   new_context->dest_window = event->any.window;
-  g_object_ref (new_context->dest_window);
+  g_object_ref_and_context (new_context->dest_window);
 
   new_context->targets = NULL;
   if (get_types)
@@ -2771,7 +2771,7 @@ xdnd_enter_filter (GdkXEvent *xev,
 
   event->dnd.type = GDK_DRAG_ENTER;
   event->dnd.context = new_context;
-  g_object_ref (new_context);
+  g_object_ref_and_context (event->dnd.context);
 
   display_x11->current_dest_drag = new_context;
 
@@ -2851,7 +2851,7 @@ xdnd_position_filter (GdkXEvent *xev,
     {
       event->dnd.type = GDK_DRAG_MOTION;
       event->dnd.context = display_x11->current_dest_drag;
-      g_object_ref (display_x11->current_dest_drag);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = time;
 
@@ -2906,7 +2906,7 @@ xdnd_drop_filter (GdkXEvent *xev,
       event->dnd.type = GDK_DROP_START;
 
       event->dnd.context = display_x11->current_dest_drag;
-      g_object_ref (display_x11->current_dest_drag);
+      g_object_ref_and_context (event->dnd.context);
 
       event->dnd.time = time;
       event->dnd.x_root = private->last_x;
@@ -2964,7 +2964,7 @@ gdk_drag_do_leave (GdkDragContext *conte
 	  break;
 	}
 
-      g_object_unref (context->dest_window);
+      g_object_unref_and_context (context->dest_window);
       context->dest_window = NULL;
     }
 }
@@ -2991,7 +2991,7 @@ gdk_drag_begin (GdkWindow     *window,
   new_context = gdk_drag_context_new ();
   new_context->is_source = TRUE;
   new_context->source_window = window;
-  g_object_ref (window);
+  g_object_ref_and_context (new_context->source_window);
 
   new_context->targets = g_list_copy (targets);
   precache_target_list (new_context);
@@ -3329,7 +3329,7 @@ gdk_drag_motion (GdkDragContext *context
 	{
 	  context->dest_window = dest_window;
 	  private->drop_xid = private->dest_xid;
-	  g_object_ref (context->dest_window);
+	  g_object_ref_and_context (context->dest_window);
 	  context->protocol = protocol;
 
 	  switch (protocol)
Index: gdk/x11/gdkdrawable-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkdrawable-x11.c,v
retrieving revision 1.61
diff -u -p -r1.61 gdkdrawable-x11.c
--- gdk/x11/gdkdrawable-x11.c	14 May 2006 03:58:06 -0000	1.61
+++ gdk/x11/gdkdrawable-x11.c	19 Jul 2006 22:40:32 -0000
@@ -186,8 +186,13 @@ _gdk_drawable_impl_x11_init (GdkDrawable
 static void
 gdk_drawable_impl_x11_finalize (GObject *object)
 {
+  GdkDrawableImplX11 *impl = GDK_DRAWABLE_IMPL_X11 (object);
+
   gdk_drawable_set_colormap (GDK_DRAWABLE (object), NULL);
 
+  if (impl->screen)
+    g_object_unref_and_context (impl->screen);
+
   G_OBJECT_CLASS (_gdk_drawable_impl_x11_parent_class)->finalize (object);
 }
 
@@ -419,10 +424,10 @@ gdk_x11_set_colormap (GdkDrawable *drawa
     return;
   
   if (impl->colormap)
-    g_object_unref (impl->colormap);
+    g_object_unref_and_context (impl->colormap);
   impl->colormap = colormap;
   if (impl->colormap)
-    g_object_ref (impl->colormap);
+    g_object_ref_and_context (impl->colormap);
 }
 
 /* Drawing
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.171
diff -u -p -r1.171 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	29 Jun 2006 15:13:56 -0000	1.171
+++ gdk/x11/gdkevents-x11.c	19 Jul 2006 22:40:35 -0000
@@ -955,7 +955,7 @@ gdk_event_translate (GdkDisplay *display
 	    }
 	}
 
-      g_object_ref (window);
+      g_object_ref_and_context (window);
     }
 
   event->any.window = window;
@@ -977,12 +977,12 @@ gdk_event_translate (GdkDisplay *display
 
       if (filter_private->filters)
 	{
-	  g_object_ref (filter_window);
+	  g_object_ref_and_context (filter_window);
 	  
 	  result = gdk_event_apply_filters (xevent, event,
 					    filter_private->filters);
 	  
-	  g_object_unref (filter_window);
+	  g_object_unref_and_context (filter_window);
       
 	  if (result != GDK_FILTER_CONTINUE)
 	    {
@@ -1727,8 +1727,9 @@ gdk_event_translate (GdkDisplay *display
       
     case DestroyNotify:
       GDK_NOTE (EVENTS,
-		g_message ("destroy notify:\twindow: %ld",
-			   xevent->xdestroywindow.window));
+		g_message ("destroy notify:\twindow: %ld, event: %ld",
+			   xevent->xdestroywindow.window,
+			   xevent->xdestroywindow.event));
 
       /* Ignore DestroyNotify from SubstructureNotifyMask */
       if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
@@ -2118,11 +2119,11 @@ gdk_event_translate (GdkDisplay *display
   if (return_val)
     {
       if (event->any.window)
-	g_object_ref (event->any.window);
+	g_object_ref_and_context (event->any.window);
       if (((event->any.type == GDK_ENTER_NOTIFY) ||
 	   (event->any.type == GDK_LEAVE_NOTIFY)) &&
 	  (event->crossing.subwindow != NULL))
-	g_object_ref (event->crossing.subwindow);
+	g_object_ref_and_context (event->crossing.subwindow);
     }
   else
     {
@@ -2132,7 +2133,7 @@ gdk_event_translate (GdkDisplay *display
     }
   
   if (window)
-    g_object_unref (window);
+    g_object_unref_and_context (window);
   
   return return_val;
 }
@@ -2899,7 +2900,7 @@ gdk_screen_get_setting (GdkScreen   *scr
 {
 
   const char *xsettings_name = NULL;
-  XSettingsResult result;
+  XSettingsResult result = XSETTINGS_NO_ENTRY;
   XSettingsSetting *setting = NULL;
   GdkScreenX11 *screen_x11;
   gboolean success = FALSE;
@@ -2917,11 +2918,9 @@ gdk_screen_get_setting (GdkScreen   *scr
 	break;
       }
 
-  if (!xsettings_name)
-    goto out;
-
-  result = xsettings_client_get_setting (screen_x11->xsettings_client, 
-					 xsettings_name, &setting);
+  if (xsettings_name && screen_x11->xsettings_client)
+    result = xsettings_client_get_setting (screen_x11->xsettings_client, 
+	xsettings_name, &setting);
   if (result != XSETTINGS_SUCCESS)
     goto out;
 
@@ -3009,7 +3008,7 @@ gdk_xsettings_watch_cb (Window   window,
       if (!gdkwin)
 	gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
       else
-	g_object_ref (gdkwin);
+	g_object_ref_with_context (gdkwin, gdk_xsettings_watch_cb);
       
       gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
     }
@@ -3017,7 +3016,7 @@ gdk_xsettings_watch_cb (Window   window,
     {
       g_assert (gdkwin);
       gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
-      g_object_unref (gdkwin);
+      g_object_unref_with_context (gdkwin, gdk_xsettings_watch_cb);
     }
 }
 
Index: gdk/x11/gdkgc-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkgc-x11.c,v
retrieving revision 1.42
diff -u -p -r1.42 gdkgc-x11.c
--- gdk/x11/gdkgc-x11.c	14 May 2006 03:58:06 -0000	1.42
+++ gdk/x11/gdkgc-x11.c	19 Jul 2006 22:40:35 -0000
@@ -79,9 +79,13 @@ _gdk_gc_x11_init (GdkGCX11 *gc)
 static void
 gdk_gc_x11_finalize (GObject *object)
 {
-  GdkGCX11 *x11_gc = GDK_GC_X11 (object);
+  GdkGCX11 *gc = GDK_GC_X11 (object);
+  Display *xdisplay = GDK_GC_XDISPLAY (gc);
   
-  XFreeGC (GDK_GC_XDISPLAY (x11_gc), GDK_GC_XGC (x11_gc));
+  if (xdisplay)
+    XFreeGC (xdisplay, GDK_GC_XGC (gc));
+    
+  g_object_unref_and_context (gc->screen);
 
   G_OBJECT_CLASS (_gdk_gc_x11_parent_class)->finalize (object);
 }
@@ -111,7 +115,8 @@ _gdk_x11_gc_new (GdkDrawable      *drawa
   private->dirty_mask = 0;
   private->have_clip_mask = FALSE;
     
-  private->screen = GDK_DRAWABLE_IMPL_X11 (drawable)->screen;
+  private->screen = g_object_ref_with_context (
+      GDK_DRAWABLE_IMPL_X11 (drawable)->screen, &private->screen);
 
   private->depth = gdk_drawable_get_depth (drawable);
 
Index: gdk/x11/gdkpixmap-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkpixmap-x11.c,v
retrieving revision 1.71
diff -u -p -r1.71 gdkpixmap-x11.c
--- gdk/x11/gdkpixmap-x11.c	14 May 2006 03:58:06 -0000	1.71
+++ gdk/x11/gdkpixmap-x11.c	19 Jul 2006 22:40:36 -0000
@@ -122,6 +122,7 @@ gdk_pixmap_impl_x11_finalize (GObject *o
       _gdk_x11_drawable_finish (GDK_DRAWABLE (draw_impl));
     }
 
+
   G_OBJECT_CLASS (gdk_pixmap_impl_x11_parent_class)->finalize (object);
 }
 
@@ -172,6 +173,8 @@ gdk_pixmap_new (GdkDrawable *drawable,
   draw_impl->wrapper = GDK_DRAWABLE (pixmap);
   
   draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
+  g_object_ref_and_context (draw_impl->screen);
+
   draw_impl->xid = XCreatePixmap (GDK_PIXMAP_XDISPLAY (pixmap),
                                   GDK_WINDOW_XID (drawable),
                                   width, height, depth);
@@ -228,6 +231,8 @@ gdk_bitmap_create_from_data (GdkDrawable
   GDK_PIXMAP_OBJECT (pixmap)->depth = 1;
 
   draw_impl->screen = GDK_WINDOW_SCREEN (drawable);
+  g_object_ref_and_context (draw_impl->screen);
+
   draw_impl->xid = XCreateBitmapFromData (GDK_WINDOW_XDISPLAY (drawable),
                                           GDK_WINDOW_XID (drawable),
                                           (char *)data, width, height);
@@ -281,6 +286,8 @@ gdk_pixmap_create_from_data (GdkDrawable
   GDK_PIXMAP_OBJECT (pixmap)->depth = depth;
 
   draw_impl->screen = GDK_DRAWABLE_SCREEN (drawable);
+  g_object_ref_and_context (draw_impl->screen);
+
   draw_impl->xid = XCreatePixmapFromBitmapData (GDK_WINDOW_XDISPLAY (drawable),
                                                 GDK_WINDOW_XID (drawable),
                                                 (char *)data, width, height,
@@ -386,6 +393,8 @@ gdk_pixmap_foreign_new_for_screen (GdkSc
   xpixmap = anid;
   
   draw_impl->screen = screen;
+  g_object_ref_and_context (draw_impl->screen);
+
   draw_impl->xid = xpixmap;
 
   pix_impl->is_foreign = TRUE;
Index: gdk/x11/gdkscreen-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkscreen-x11.c,v
retrieving revision 1.50
diff -u -p -r1.50 gdkscreen-x11.c
--- gdk/x11/gdkscreen-x11.c	22 May 2006 04:11:42 -0000	1.50
+++ gdk/x11/gdkscreen-x11.c	19 Jul 2006 22:40:37 -0000
@@ -249,17 +249,19 @@ void
 gdk_screen_set_default_colormap (GdkScreen   *screen,
 				 GdkColormap *colormap)
 {
-  GdkColormap *old_colormap;
-  
   g_return_if_fail (GDK_IS_SCREEN (screen));
   g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
-  old_colormap = GDK_SCREEN_X11 (screen)->default_colormap;
+  if (colormap != GDK_SCREEN_X11 (screen)->default_colormap)
+    {
+      if (GDK_SCREEN_X11 (screen)->default_colormap)
+	g_object_unref_and_context (GDK_SCREEN_X11 (screen)->default_colormap);
 
-  GDK_SCREEN_X11 (screen)->default_colormap = g_object_ref (colormap);
+      GDK_SCREEN_X11 (screen)->default_colormap =
+	g_object_ref_with_context (colormap,
+	    &GDK_SCREEN_X11 (screen)->default_colormap);
+    }
   
-  if (old_colormap)
-    g_object_unref (old_colormap);
 }
 
 static void
@@ -271,32 +273,40 @@ gdk_screen_x11_dispose (GObject *object)
 
   if (screen_x11->default_colormap)
     {
-      g_object_unref (screen_x11->default_colormap);
+      g_object_unref_and_context (screen_x11->default_colormap);
       screen_x11->default_colormap = NULL;
     }
 
   if (screen_x11->system_colormap)
     {
-      g_object_unref (screen_x11->system_colormap);
+      g_object_unref_and_context (screen_x11->system_colormap);
       screen_x11->system_colormap = NULL;
     }
 
   if (screen_x11->rgba_colormap)
     {
-      g_object_unref (screen_x11->rgba_colormap);
+      g_object_unref_with_context (screen_x11->rgba_colormap, screen_x11->rgba_colormap);
       screen_x11->rgba_colormap = NULL;
     }
 
   if (screen_x11->root_window)
-    _gdk_window_destroy (screen_x11->root_window, TRUE);
+    {
+      _gdk_window_destroy (screen_x11->root_window, TRUE);
+      _gdk_xid_table_remove (screen_x11->display, screen_x11->root_window);
+      g_object_unref_with_context (screen_x11->root_window, screen_x11->root_window);
+      screen_x11->root_window = NULL;
+    }
+
 
   G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->dispose (object);
 
+#if 0
   screen_x11->xdisplay = NULL;
-  screen_x11->xscreen = NULL;
+  screen_x11->xscreen = 0;
   screen_x11->screen_num = -1;
   screen_x11->xroot_window = None;
   screen_x11->wmspec_check_window = None;
+#endif
 }
 
 static void
@@ -323,6 +333,8 @@ gdk_screen_x11_finalize (GObject *object
 
   g_free (screen_x11->monitors);
 
+  g_object_unref_and_context (screen_x11->display);
+
   G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->finalize (object);
 }
 
@@ -496,7 +508,9 @@ _gdk_x11_screen_new (GdkDisplay *display
   screen = g_object_new (GDK_TYPE_SCREEN_X11, NULL);
 
   screen_x11 = GDK_SCREEN_X11 (screen);
-  screen_x11->display = display;
+
+  /* circular reference broken by explicit calls to dispose */
+  screen_x11->display = g_object_ref_with_context (display, &screen_x11->display);
   screen_x11->xdisplay = display_x11->xdisplay;
   screen_x11->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number);
   screen_x11->screen_num = screen_number;
Index: gdk/x11/gdkwindow-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.c,v
retrieving revision 1.263
diff -u -p -r1.263 gdkwindow-x11.c
--- gdk/x11/gdkwindow-x11.c	20 Jun 2006 04:30:11 -0000	1.263
+++ gdk/x11/gdkwindow-x11.c	19 Jul 2006 22:40:43 -0000
@@ -436,10 +436,11 @@ _gdk_windowing_window_init (GdkScreen * 
   draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
   
   draw_impl->screen = screen;
+  g_object_ref_and_context (draw_impl->screen);
   draw_impl->xid = screen_x11->xroot_window;
   draw_impl->wrapper = GDK_DRAWABLE (private);
   draw_impl->colormap = gdk_screen_get_system_colormap (screen);
-  g_object_ref (draw_impl->colormap);
+  g_object_ref_and_context (draw_impl->colormap);
   
   private->window_type = GDK_WINDOW_ROOT;
   private->depth = DefaultDepthOfScreen (screen_x11->xscreen);
@@ -688,6 +689,7 @@ gdk_window_new (GdkWindow     *parent,
   draw_impl->wrapper = GDK_DRAWABLE (window);
   
   draw_impl->screen = screen;
+  g_object_ref_and_context (draw_impl->screen);
   xdisplay = screen_x11->xdisplay;
 
   /* Windows with a foreign parent are treated as if they are children
@@ -811,18 +813,20 @@ gdk_window_new (GdkWindow     *parent,
       if (attributes_mask & GDK_WA_COLORMAP)
         {
           draw_impl->colormap = attributes->colormap;
-          g_object_ref (attributes->colormap);
+          g_object_ref_and_context (draw_impl->colormap);
         }
       else
 	{
 	  if ((((GdkVisualPrivate *)gdk_screen_get_system_visual (screen))->xvisual) ==  xvisual)
             {
 	      draw_impl->colormap = gdk_screen_get_system_colormap (screen);
-              g_object_ref (draw_impl->colormap);
+              g_object_ref_and_context (draw_impl->colormap);
             }
 	  else
             {
               draw_impl->colormap = gdk_colormap_new (visual, FALSE);
+	      g_object_ref_set_context (draw_impl->colormap,
+		  draw_impl->colormap, &draw_impl->colormap);
             }
 	}
       
@@ -862,7 +866,7 @@ gdk_window_new (GdkWindow     *parent,
       class = InputOnly;
       private->input_only = TRUE;
       draw_impl->colormap = gdk_screen_get_system_colormap (screen);
-      g_object_ref (draw_impl->colormap);
+      g_object_ref_and_context (draw_impl->colormap);
     }
 
   xid = draw_impl->xid = XCreateWindow (xdisplay, xparent,
@@ -871,7 +875,7 @@ gdk_window_new (GdkWindow     *parent,
 					0, depth, class, xvisual,
 					xattributes_mask, &xattributes);
 
-  g_object_ref (window);
+  g_object_ref_with_context (window, screen_x11->display);
   _gdk_xid_table_insert (screen_x11->display, &draw_impl->xid, window);
   
   gdk_window_set_cursor (window, ((attributes_mask & GDK_WA_CURSOR) ?
@@ -999,6 +1003,7 @@ gdk_window_foreign_new_for_display (GdkD
   draw_impl = GDK_DRAWABLE_IMPL_X11 (private->impl);
   draw_impl->wrapper = GDK_DRAWABLE (window);
   draw_impl->screen = _gdk_x11_display_screen_for_xrootwin (display, root);
+  g_object_ref_and_context (draw_impl->screen);
   
   private->parent = gdk_xid_table_lookup_for_display (display, parent);
   
@@ -1027,7 +1032,7 @@ gdk_window_foreign_new_for_display (GdkD
   
   _gdk_window_init_position (GDK_WINDOW (private));
 
-  g_object_ref (window);
+  g_object_ref_with_context (window, display);
   _gdk_xid_table_insert (display, &GDK_WINDOW_XID (window), window);
   return window;
 }
@@ -1077,22 +1082,22 @@ gdk_toplevel_x11_free_contents (GdkDispl
 {
   if (toplevel->icon_window)
     {
-      g_object_unref (toplevel->icon_window);
+      g_object_unref_and_context (toplevel->icon_window);
       toplevel->icon_window = NULL;
     }
   if (toplevel->icon_pixmap)
     {
-      g_object_unref (toplevel->icon_pixmap);
+      g_object_unref_and_context (toplevel->icon_pixmap);
       toplevel->icon_pixmap = NULL;
     }
   if (toplevel->icon_mask)
     {
-      g_object_unref (toplevel->icon_mask);
+      g_object_unref_and_context (toplevel->icon_mask);
       toplevel->icon_mask = NULL;
     }
   if (toplevel->group_leader)
     {
-      g_object_unref (toplevel->group_leader);
+      g_object_unref_and_context (toplevel->group_leader);
       toplevel->group_leader = NULL;
     }
 #ifdef HAVE_XSYNC
@@ -1199,7 +1204,7 @@ gdk_window_destroy_notify (GdkWindow *wi
 
   _gdk_xgrab_check_destroy (window);
   
-  g_object_unref (window);
+  g_object_unref_with_context (window, GDK_WINDOW_DISPLAY (window));
 }
 
 static void
@@ -2944,7 +2949,7 @@ gdk_window_set_background (GdkWindow    
   if (private->bg_pixmap &&
       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
       private->bg_pixmap != GDK_NO_BG)
-    g_object_unref (private->bg_pixmap);
+    g_object_unref_and_context (private->bg_pixmap);
   
   private->bg_pixmap = NULL;
 }
@@ -2994,7 +2999,7 @@ gdk_window_set_back_pixmap (GdkWindow *w
   if (private->bg_pixmap &&
       private->bg_pixmap != GDK_PARENT_RELATIVE_BG &&
       private->bg_pixmap != GDK_NO_BG)
-    g_object_unref (private->bg_pixmap);
+    g_object_unref_and_context (private->bg_pixmap);
 
   if (parent_relative)
     {
@@ -3005,8 +3010,7 @@ gdk_window_set_back_pixmap (GdkWindow *w
     {
       if (pixmap)
 	{
-	  g_object_ref (pixmap);
-	  private->bg_pixmap = pixmap;
+	  private->bg_pixmap = g_object_ref_with_context (pixmap, &private->bg_pixmap);
 	  xpixmap = GDK_PIXMAP_XID (pixmap);
 	}
       else
@@ -4378,26 +4382,26 @@ gdk_window_set_icon (GdkWindow *window, 
   if (toplevel->icon_window != icon_window)
     {
       if (toplevel->icon_window)
-	g_object_unref (toplevel->icon_window);
-      toplevel->icon_window = g_object_ref (icon_window);
+	g_object_unref_and_context (toplevel->icon_window);
+      toplevel->icon_window = g_object_ref_with_context (icon_window, &toplevel->icon_window);
     }
   
   if (toplevel->icon_pixmap != pixmap)
     {
-      if (pixmap)
-	g_object_ref (pixmap);
       if (toplevel->icon_pixmap)
-	g_object_unref (toplevel->icon_pixmap);
+	g_object_unref_and_context (toplevel->icon_pixmap);
       toplevel->icon_pixmap = pixmap;
+      if (toplevel->icon_pixmap)
+	g_object_ref_and_context (toplevel->icon_pixmap);
     }
   
   if (toplevel->icon_mask != mask)
     {
-      if (mask)
-	g_object_ref (mask);
       if (toplevel->icon_mask)
-	g_object_unref (toplevel->icon_mask);
+	g_object_unref_and_context (toplevel->icon_mask);
       toplevel->icon_mask = mask;
+      if (toplevel->icon_mask)
+	g_object_ref_and_context (toplevel->icon_mask);
     }
   
   update_wm_hints (window, FALSE);
@@ -4904,8 +4908,8 @@ gdk_window_set_group (GdkWindow *window,
   if (toplevel->group_leader != leader)
     {
       if (toplevel->group_leader)
-	g_object_unref (toplevel->group_leader);
-      toplevel->group_leader = g_object_ref (leader);
+	g_object_unref_and_context (toplevel->group_leader);
+      toplevel->group_leader = g_object_ref_with_context (leader, &toplevel->group_leader);
       (_gdk_x11_window_get_toplevel (leader))->is_leader = TRUE;      
     }
 
@@ -5829,7 +5833,7 @@ finish_drag (MoveResizeData *mv_resize)
 {
   gdk_window_destroy (mv_resize->moveresize_emulation_window);
   mv_resize->moveresize_emulation_window = NULL;
-  g_object_unref (mv_resize->moveresize_window);
+  g_object_unref_and_context (mv_resize->moveresize_window);
   mv_resize->moveresize_window = NULL;
 
   if (mv_resize->moveresize_pending_event)
@@ -6102,7 +6106,7 @@ emulate_resize_drag (GdkWindow     *wind
   mv_resize->resize_edge = edge;
   mv_resize->moveresize_x = root_x;
   mv_resize->moveresize_y = root_y;
-  mv_resize->moveresize_window = g_object_ref (window);
+  mv_resize->moveresize_window = g_object_ref_with_context (window, &mv_resize->moveresize_window);
 
   gdk_drawable_get_size (window,
 			 &mv_resize->moveresize_orig_width,
@@ -6132,7 +6136,7 @@ emulate_move_drag (GdkWindow     *window
   mv_resize->moveresize_x = root_x;
   mv_resize->moveresize_y = root_y;
 
-  mv_resize->moveresize_window = g_object_ref (window);
+  mv_resize->moveresize_window = g_object_ref_with_context (window, &mv_resize->moveresize_window);
 
   calculate_unmoving_origin (mv_resize);
 
Index: gtk/Makefile.am
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/Makefile.am,v
retrieving revision 1.312
diff -u -p -r1.312 Makefile.am
--- gtk/Makefile.am	2 Jul 2006 14:40:43 -0000	1.312
+++ gtk/Makefile.am	19 Jul 2006 22:40:44 -0000
@@ -89,6 +89,9 @@ gtkalias.h: gtk.symbols
 gtkaliasdef.c: gtk.symbols
 	  $(PERL) $(srcdir)/makegtkalias.pl -def < $(srcdir)/gtk.symbols > gtkaliasdef.c
 
+_gtk_icon_cache_missing_pb.c: stock-icons/24/gtk-missing-image.png
+	  $(top_builddir)/gdk-pixbuf/gdk-pixbuf-csource --rle --static --struct --name _gtk_icon_cache_missing_pb stock-icons/24/gtk-missing-image.png > $@
+
 if OS_LINUX
 TESTS = abicheck.sh
 endif
@@ -661,6 +664,7 @@ gtk_built_private_headers =			\
 
 gtk_built_sources =				\
 	gtkaliasdef.c				\
+	_gtk_icon_cache_missing_pb.c		\
 	gtktypebuiltins.c			\
 	gtkmarshalers.c				\
 	gtkmarshalers.h				\
Index: gtk/gtkaccelgroup.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkaccelgroup.c,v
retrieving revision 1.66
diff -u -p -r1.66 gtkaccelgroup.c
--- gtk/gtkaccelgroup.c	14 May 2006 04:25:28 -0000	1.66
+++ gtk/gtkaccelgroup.c	19 Jul 2006 22:40:45 -0000
@@ -175,7 +175,7 @@ accel_group_weak_ref_detach (GSList  *fr
       
       accel_group = slist->data;
       accel_group->acceleratables = g_slist_remove (accel_group->acceleratables, stale_object);
-      g_object_unref (accel_group);
+      g_object_unref_with_context (accel_group, stale_object);
     }
   g_slist_free (free_list);
   g_object_set_qdata (stale_object, quark_acceleratable_groups, NULL);
@@ -191,7 +191,7 @@ _gtk_accel_group_attach (GtkAccelGroup *
   g_return_if_fail (G_IS_OBJECT (object));
   g_return_if_fail (g_slist_find (accel_group->acceleratables, object) == NULL);
   
-  g_object_ref (accel_group);
+  g_object_ref_with_context (accel_group, object);
   accel_group->acceleratables = g_slist_prepend (accel_group->acceleratables, object);
   slist = g_object_get_qdata (object, quark_acceleratable_groups);
   if (slist)
@@ -267,7 +267,7 @@ gtk_accel_group_find (GtkAccelGroup     
   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
   g_return_val_if_fail (find_func != NULL, NULL);
 
-  g_object_ref (accel_group);
+  g_object_ref_and_context (accel_group);
   for (i = 0; i < accel_group->n_accels; i++)
     if (find_func (&accel_group->priv_accels[i].key,
 		   accel_group->priv_accels[i].closure,
@@ -276,7 +276,7 @@ gtk_accel_group_find (GtkAccelGroup     
 	key = &accel_group->priv_accels[i].key;
 	break;
       }
-  g_object_unref (accel_group);
+  g_object_unref_and_context (accel_group);
 
   return key;
 }
@@ -500,12 +500,12 @@ gtk_accel_group_connect (GtkAccelGroup	*
   g_return_if_fail (accel_key > 0);
   g_return_if_fail (gtk_accel_group_from_accel_closure (closure) == NULL);
 
-  g_object_ref (accel_group);
+  g_object_ref_and_context (accel_group);
   if (!closure->is_invalid)
     quick_accel_add (accel_group,
 		     gdk_keyval_to_lower (accel_key),
 		     accel_mods, accel_flags, closure, 0);
-  g_object_unref (accel_group);
+  g_object_unref_and_context (accel_group);
 }
 
 /**
@@ -539,7 +539,7 @@ gtk_accel_group_connect_by_path (GtkAcce
   if (closure->is_invalid)
     return;
 
-  g_object_ref (accel_group);
+  g_object_ref_and_context (accel_group);
 
   if (gtk_accel_map_lookup_entry (accel_path, &key))
     {
@@ -550,7 +550,7 @@ gtk_accel_group_connect_by_path (GtkAcce
   quick_accel_add (accel_group, accel_key, accel_mods, GTK_ACCEL_VISIBLE, closure,
 		   g_quark_from_string (accel_path));
 
-  g_object_unref (accel_group);
+  g_object_unref_and_context (accel_group);
 }
 
 /**
@@ -573,9 +573,9 @@ gtk_accel_group_disconnect (GtkAccelGrou
   for (i = 0; i < accel_group->n_accels; i++)
     if (accel_group->priv_accels[i].closure == closure)
       {
-	g_object_ref (accel_group);
+	g_object_ref_and_context (accel_group);
 	quick_accel_remove (accel_group, accel_group->priv_accels + i);
-	g_object_unref (accel_group);
+	g_object_unref_and_context (accel_group);
 	return TRUE;
       }
   return FALSE;
@@ -604,7 +604,7 @@ gtk_accel_group_disconnect_key (GtkAccel
 
   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
 
-  g_object_ref (accel_group);
+  g_object_ref_and_context (accel_group);
   
   accel_key = gdk_keyval_to_lower (accel_key);
   entries = quick_accel_find (accel_group, accel_key, accel_mods, &n);
@@ -624,7 +624,7 @@ gtk_accel_group_disconnect_key (GtkAccel
     }
   g_slist_free (clist);
 
-  g_object_unref (accel_group);
+  g_object_unref_and_context (accel_group);
 
   return removed_one;
 }
@@ -638,7 +638,7 @@ _gtk_accel_group_reconnect (GtkAccelGrou
 
   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
 
-  g_object_ref (accel_group);
+  g_object_ref_and_context (accel_group);
 
   for (i = 0; i < accel_group->n_accels; i++)
     if (accel_group->priv_accels[i].accel_path_quark == accel_path_quark)
@@ -658,7 +658,7 @@ _gtk_accel_group_reconnect (GtkAccelGrou
     }
   g_slist_free (clist);
 
-  g_object_unref (accel_group);
+  g_object_unref_and_context (accel_group);
 }
 
 /**
Index: gtk/gtkaccellabel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkaccellabel.c,v
retrieving revision 1.73
diff -u -p -r1.73 gtkaccellabel.c
--- gtk/gtkaccellabel.c	14 May 2006 04:25:28 -0000	1.73
+++ gtk/gtkaccellabel.c	19 Jul 2006 22:40:46 -0000
@@ -393,12 +393,12 @@ gtk_accel_label_set_accel_widget (GtkAcc
 	  g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
 						refetch_widget_accel_closure,
 						accel_label);
-	  g_object_unref (accel_label->accel_widget);
+	  g_object_unref_and_context (accel_label->accel_widget);
 	}
       accel_label->accel_widget = accel_widget;
       if (accel_label->accel_widget)
 	{
-	  g_object_ref (accel_label->accel_widget);
+	  g_object_ref_and_context (accel_label->accel_widget);
 	  g_signal_connect_object (accel_label->accel_widget, "accel_closures_changed",
 				   G_CALLBACK (refetch_widget_accel_closure),
 				   accel_label, G_CONNECT_SWAPPED);
Index: gtk/gtkaccelmap.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkaccelmap.c,v
retrieving revision 1.28
diff -u -p -r1.28 gtkaccelmap.c
--- gtk/gtkaccelmap.c	6 Jul 2006 05:14:01 -0000	1.28
+++ gtk/gtkaccelmap.c	19 Jul 2006 22:40:47 -0000
@@ -389,7 +389,7 @@ internal_change_entry (const gchar    *a
     {
       /* ref accel groups */
       for (slist = group_list; slist; slist = slist->next)
-	g_object_ref (slist->data);
+	g_object_ref_and_context (slist->data);
 
       /* 8) remove existing accelerators */
       for (slist = replace_list; slist; slist = slist->next)
@@ -405,7 +405,7 @@ internal_change_entry (const gchar    *a
 
       /* unref accel groups */
       for (slist = group_list; slist; slist = slist->next)
-	g_object_unref (slist->data);
+	g_object_unref_and_context (slist->data);
 
       do_accel_map_changed (entry);
     }
Index: gtk/gtkaction.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkaction.c,v
retrieving revision 1.70
diff -u -p -r1.70 gtkaction.c
--- gtk/gtkaction.c	10 Jul 2006 16:59:42 -0000	1.70
+++ gtk/gtkaction.c	19 Jul 2006 22:40:48 -0000
@@ -418,7 +418,7 @@ gtk_action_finalize (GObject *object)
 
   g_closure_unref (action->private_data->accel_closure);
   if (action->private_data->accel_group)
-    g_object_unref (action->private_data->accel_group);
+    g_object_unref_and_context (action->private_data->accel_group);
 
   G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);  
 }
@@ -642,12 +642,18 @@ gtk_action_create_menu_proxy (GtkToolIte
 }
 
 static void
+action_unref (gpointer ptr)
+{
+  g_object_unref_with_context (ptr, action_unref);
+}
+
+static void
 connect_proxy (GtkAction     *action, 
 	       GtkWidget     *proxy)
 {
-  g_object_ref (action);
+  g_object_ref_with_context (action, action_unref);
   g_object_set_qdata_full (G_OBJECT (proxy), quark_gtk_action_proxy, action,
-			   g_object_unref);
+			   action_unref);
 
   /* add this widget to the list of proxies */
   action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
@@ -828,7 +834,7 @@ _gtk_action_emit_activate (GtkAction *ac
 
   if (group != NULL) 
     {
-      g_object_ref (group);
+      g_object_ref_and_context (group);
       _gtk_action_group_emit_pre_activate (group, action);
     }
 
@@ -837,7 +843,7 @@ _gtk_action_emit_activate (GtkAction *ac
   if (group != NULL) 
     {
       _gtk_action_group_emit_post_activate (group, action);
-      g_object_unref (group);
+      g_object_unref_and_context (group);
     }
 }
 
@@ -1699,13 +1705,17 @@ gtk_action_set_accel_group (GtkAction   
 {
   g_return_if_fail (GTK_IS_ACTION (action));
   g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
-  
-  if (accel_group)
-    g_object_ref (accel_group);
-  if (action->private_data->accel_group)
-    g_object_unref (action->private_data->accel_group);
 
-  action->private_data->accel_group = accel_group;
+  if(action->private_data->accel_group != accel_group)
+    {
+      if (action->private_data->accel_group)
+	g_object_unref_and_context (action->private_data->accel_group);
+
+      action->private_data->accel_group = accel_group;
+
+      if (accel_group)
+	g_object_ref_and_context (action->private_data->accel_group);
+    }
 }
 
 /**
Index: gtk/gtkactiongroup.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkactiongroup.c,v
retrieving revision 1.59
diff -u -p -r1.59 gtkactiongroup.c
--- gtk/gtkactiongroup.c	22 Jun 2006 15:56:55 -0000	1.59
+++ gtk/gtkactiongroup.c	19 Jul 2006 22:40:50 -0000
@@ -254,7 +254,7 @@ static void 
 remove_action (GtkAction *action) 
 {
   g_object_set (action, I_("action-group"), NULL, NULL);
-  g_object_unref (action);
+  g_object_unref_with_context (action, remove_action);
 }
 
 static void
@@ -559,7 +559,7 @@ gtk_action_group_add_action (GtkActionGr
 
   g_hash_table_insert (action_group->private_data->actions, 
 		       g_strdup (gtk_action_get_name (action)),
-                       g_object_ref (action));
+                       g_object_ref_with_context (action, remove_action));
   g_object_set (action, I_("action-group"), action_group, NULL);
 }
 
@@ -645,9 +645,9 @@ gtk_action_group_remove_action (GtkActio
   g_return_if_fail (gtk_action_get_name (action) != NULL);
 
   /* extra protection to make sure action->name is valid */
-  g_object_ref (action);
+  g_object_ref_and_context (action);
   g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
-  g_object_unref (action);
+  g_object_unref_and_context (action);
 }
 
 static void
Index: gtk/gtkbindings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbindings.c,v
retrieving revision 1.54
diff -u -p -r1.54 gtkbindings.c
--- gtk/gtkbindings.c	23 Mar 2006 23:21:30 -0000	1.54
+++ gtk/gtkbindings.c	19 Jul 2006 22:40:51 -0000
@@ -67,7 +67,7 @@ pattern_spec_free (PatternSpec *pspec)
   _gtk_rc_free_widget_class_path (pspec->path);
   if (pspec->pspec)
     g_pattern_spec_free (pspec->pspec);
-  g_free (pspec);
+  g_slice_free (PatternSpec, pspec);
 }
 
 static GtkBindingSignal*
@@ -200,7 +200,7 @@ binding_entry_new (GtkBindingSet  *bindi
   if (!binding_entry_hash_table)
     binding_entry_hash_table = g_hash_table_new (binding_entry_hash, binding_entries_compare);
 
-  entry = g_new (GtkBindingEntry, 1);
+  entry = g_slice_new (GtkBindingEntry);
   entry->keyval = keyval;
   entry->modifiers = modifiers;
   entry->binding_set = binding_set,
@@ -246,7 +246,7 @@ binding_entry_free (GtkBindingEntry *ent
       sig = prev->next;
       binding_signal_free (prev);
     }
-  g_free (entry);
+  g_slice_free (GtkBindingEntry, entry);
 }
 
 static void
@@ -478,7 +478,7 @@ gtk_binding_entry_activate (GtkBindingEn
   old_emission = entry->in_emission;
   entry->in_emission = TRUE;
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   
   for (sig = entry->signals; sig; sig = sig->next)
     {
@@ -551,7 +551,7 @@ gtk_binding_entry_activate (GtkBindingEn
 	break;
     }
   
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 
   entry->in_emission = old_emission;
   if (entry->destroyed && !entry->in_emission)
@@ -879,7 +879,7 @@ gtk_binding_set_add_path (GtkBindingSet	
       break;
     }
   
-  pspec = g_new (PatternSpec, 1);
+  pspec = g_slice_new (PatternSpec);
   pspec->type = path_type;
   if (path_type == GTK_PATH_WIDGET_CLASS)
     {
@@ -1221,7 +1221,7 @@ gtk_binding_parse_signal (GScanner      
 	  if (need_arg)
 	    {
 	      need_arg = FALSE;
-	      arg = g_new (GtkBindingArg, 1);
+	      arg = g_slice_new (GtkBindingArg);
 	      arg->arg_type = G_TYPE_DOUBLE;
 	      arg->d.double_data = scanner->value.v_float;
 	      if (negate)
@@ -1238,7 +1238,7 @@ gtk_binding_parse_signal (GScanner      
 	  if (need_arg)
 	    {
 	      need_arg = FALSE;
-	      arg = g_new (GtkBindingArg, 1);
+	      arg = g_slice_new (GtkBindingArg);
 	      arg->arg_type = G_TYPE_LONG;
 	      arg->d.long_data = scanner->value.v_int;
 	      if (negate)
@@ -1255,7 +1255,7 @@ gtk_binding_parse_signal (GScanner      
 	  if (need_arg && !negate)
 	    {
 	      need_arg = FALSE;
-	      arg = g_new (GtkBindingArg, 1);
+	      arg = g_slice_new (GtkBindingArg);
 	      arg->arg_type = G_TYPE_STRING;
 	      arg->d.string_data = g_strdup (scanner->value.v_string);
 	      args = g_slist_prepend (args, arg);
@@ -1267,7 +1267,7 @@ gtk_binding_parse_signal (GScanner      
 	  if (need_arg && !negate)
 	    {
 	      need_arg = FALSE;
-	      arg = g_new (GtkBindingArg, 1);
+	      arg = g_slice_new (GtkBindingArg);
 	      arg->arg_type = GTK_TYPE_IDENTIFIER;
 	      arg->d.string_data = g_strdup (scanner->value.v_identifier);
 	      args = g_slist_prepend (args, arg);
@@ -1321,7 +1321,7 @@ gtk_binding_parse_signal (GScanner      
       arg = slist->data;
       if (G_TYPE_FUNDAMENTAL (arg->arg_type) == G_TYPE_STRING)
 	g_free (arg->d.string_data);
-      g_free (arg);
+      g_slice_free (GtkBindingArg, arg);
     }
   g_slist_free (args);
   g_free (signal);
Index: gtk/gtkbox.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbox.c,v
retrieving revision 1.58
diff -u -p -r1.58 gtkbox.c
--- gtk/gtkbox.c	14 May 2006 04:25:28 -0000	1.58
+++ gtk/gtkbox.c	19 Jul 2006 22:40:52 -0000
@@ -342,7 +342,7 @@ gtk_box_pack_start (GtkBox    *box,
   g_return_if_fail (GTK_IS_WIDGET (child));
   g_return_if_fail (child->parent == NULL);
 
-  child_info = g_new (GtkBoxChild, 1);
+  child_info = g_slice_new (GtkBoxChild);
   child_info->widget = child;
   child_info->padding = padding;
   child_info->expand = expand ? TRUE : FALSE;
@@ -377,7 +377,7 @@ gtk_box_pack_end (GtkBox    *box,
   g_return_if_fail (GTK_IS_WIDGET (child));
   g_return_if_fail (child->parent == NULL);
 
-  child_info = g_new (GtkBoxChild, 1);
+  child_info = g_slice_new (GtkBoxChild);
   child_info->widget = child;
   child_info->padding = padding;
   child_info->expand = expand ? TRUE : FALSE;
@@ -631,7 +631,7 @@ gtk_box_remove (GtkContainer *container,
 
 	  box->children = g_list_remove_link (box->children, children);
 	  g_list_free (children);
-	  g_free (child);
+	  g_slice_free (GtkBoxChild, child);
 
 	  /* queue resize regardless of GTK_WIDGET_VISIBLE (container),
 	   * since that's what is needed by toplevels.
Index: gtk/gtkbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkbutton.c,v
retrieving revision 1.144
diff -u -p -r1.144 gtkbutton.c
--- gtk/gtkbutton.c	8 Jun 2006 12:47:05 -0000	1.144
+++ gtk/gtkbutton.c	19 Jul 2006 22:40:53 -0000
@@ -730,7 +730,7 @@ gtk_button_construct_child (GtkButton *b
 
   if (priv->image && !priv->image_is_stock)
     {
-      image = g_object_ref (priv->image);
+      image = g_object_ref_with_context (priv->image, &image);
       if (image->parent)
 	gtk_container_remove (GTK_CONTAINER (image->parent), image);
       
@@ -746,7 +746,7 @@ gtk_button_construct_child (GtkButton *b
       gtk_stock_lookup (button->label_text, &item))
     {
       if (!image)
-	image = g_object_ref (gtk_image_new_from_stock (button->label_text, GTK_ICON_SIZE_BUTTON));
+	image = g_object_ref_with_context (gtk_image_new_from_stock (button->label_text, GTK_ICON_SIZE_BUTTON), &image);
 
       label_text = item.label;
     }
@@ -795,7 +795,7 @@ gtk_button_construct_child (GtkButton *b
       gtk_container_add (GTK_CONTAINER (align), box);
       gtk_widget_show_all (align);
 
-      g_object_unref (image);
+      g_object_unref_and_context (image);
 
       return;
     }
@@ -955,7 +955,7 @@ gtk_button_realize (GtkWidget *widget)
   attributes_mask = GDK_WA_X | GDK_WA_Y;
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   button->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 					 &attributes, attributes_mask);
Index: gtk/gtkcalendar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcalendar.c,v
retrieving revision 1.110
diff -u -p -r1.110 gtkcalendar.c
--- gtk/gtkcalendar.c	17 Jul 2006 12:55:12 -0000	1.110
+++ gtk/gtkcalendar.c	19 Jul 2006 22:40:57 -0000
@@ -1470,7 +1470,6 @@ gtk_calendar_realize (GtkWidget *widget)
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
   widget->window = gdk_window_new (widget->parent->window,
 				   &attributes, attributes_mask);
-  
   widget->style = gtk_style_attach (widget->style, widget->window);
   
   /* Header window ------------------------------------- */
Index: gtk/gtkcellrendererpixbuf.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcellrendererpixbuf.c,v
retrieving revision 1.52
diff -u -p -r1.52 gtkcellrendererpixbuf.c
--- gtk/gtkcellrendererpixbuf.c	14 May 2006 04:25:28 -0000	1.52
+++ gtk/gtkcellrendererpixbuf.c	19 Jul 2006 22:40:57 -0000
@@ -204,11 +204,11 @@ gtk_cell_renderer_pixbuf_finalize (GObje
   priv = GTK_CELL_RENDERER_PIXBUF_GET_PRIVATE (object);
   
   if (cellpixbuf->pixbuf)
-    g_object_unref (cellpixbuf->pixbuf);
+    g_object_unref_and_context (cellpixbuf->pixbuf);
   if (cellpixbuf->pixbuf_expander_open)
-    g_object_unref (cellpixbuf->pixbuf_expander_open);
+    g_object_unref_and_context (cellpixbuf->pixbuf_expander_open);
   if (cellpixbuf->pixbuf_expander_closed)
-    g_object_unref (cellpixbuf->pixbuf_expander_closed);
+    g_object_unref_and_context (cellpixbuf->pixbuf_expander_closed);
 
   g_free (priv->stock_id);
   g_free (priv->stock_detail);
@@ -276,10 +276,11 @@ gtk_cell_renderer_pixbuf_set_property (G
     {
     case PROP_PIXBUF:
       if (cellpixbuf->pixbuf)
-	g_object_unref (cellpixbuf->pixbuf);
-      cellpixbuf->pixbuf = (GdkPixbuf*) g_value_dup_object (value);
+	g_object_unref_and_context (cellpixbuf->pixbuf);
+      cellpixbuf->pixbuf = g_value_get_object (value);
       if (cellpixbuf->pixbuf)
         {
+	  g_object_ref_and_context (cellpixbuf->pixbuf);
           if (priv->stock_id)
             {
               g_free (priv->stock_id);
@@ -296,13 +297,17 @@ gtk_cell_renderer_pixbuf_set_property (G
       break;
     case PROP_PIXBUF_EXPANDER_OPEN:
       if (cellpixbuf->pixbuf_expander_open)
-	g_object_unref (cellpixbuf->pixbuf_expander_open);
-      cellpixbuf->pixbuf_expander_open = (GdkPixbuf*) g_value_dup_object (value);
+	g_object_unref_and_context (cellpixbuf->pixbuf_expander_open);
+      cellpixbuf->pixbuf_expander_open = g_value_get_object (value);
+      if (cellpixbuf->pixbuf_expander_open)
+	g_object_ref_and_context (cellpixbuf->pixbuf_expander_open);
       break;
     case PROP_PIXBUF_EXPANDER_CLOSED:
       if (cellpixbuf->pixbuf_expander_closed)
-	g_object_unref (cellpixbuf->pixbuf_expander_closed);
-      cellpixbuf->pixbuf_expander_closed = (GdkPixbuf*) g_value_dup_object (value);
+	g_object_unref_and_context (cellpixbuf->pixbuf_expander_closed);
+      cellpixbuf->pixbuf_expander_closed = g_value_get_object (value);
+      if (cellpixbuf->pixbuf_expander_closed)
+	g_object_ref_and_context (cellpixbuf->pixbuf_expander_closed);
       break;
     case PROP_STOCK_ID:
       if (priv->stock_id)
Index: gtk/gtkcellrendererspin.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcellrendererspin.c,v
retrieving revision 1.5
diff -u -p -r1.5 gtkcellrendererspin.c
--- gtk/gtkcellrendererspin.c	14 May 2006 04:25:28 -0000	1.5
+++ gtk/gtkcellrendererspin.c	19 Jul 2006 22:40:58 -0000
@@ -148,7 +148,7 @@ gtk_cell_renderer_spin_finalize (GObject
   priv = GTK_CELL_RENDERER_SPIN_GET_PRIVATE (object);
 
   if (priv && priv->adjustment)
-    g_object_unref (priv->adjustment);
+    g_object_unref_and_context (priv->adjustment);
 
   if (G_OBJECT_CLASS (gtk_cell_renderer_spin_parent_class)->finalize)
     (* G_OBJECT_CLASS (gtk_cell_renderer_spin_parent_class)->finalize) (object);
@@ -203,12 +203,12 @@ gtk_cell_renderer_spin_set_property (GOb
 
       if (priv->adjustment)
 	{
-	  g_object_unref (priv->adjustment);
+	  g_object_unref_and_context (priv->adjustment);
 	  priv->adjustment = NULL;
 	}
 
       if (obj)
-	priv->adjustment = g_object_ref (obj);
+	priv->adjustment = g_object_ref_with_context (obj, &priv->adjustment);
       break;
     case PROP_CLIMB_RATE:
       priv->climb_rate = g_value_get_double (value);
Index: gtk/gtkcellview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcellview.c,v
retrieving revision 1.47
diff -u -p -r1.47 gtkcellview.c
--- gtk/gtkcellview.c	24 May 2006 17:01:28 -0000	1.47
+++ gtk/gtkcellview.c	19 Jul 2006 22:40:59 -0000
@@ -284,7 +284,7 @@ gtk_cell_view_finalize (GObject *object)
   gtk_cell_view_cell_layout_clear (GTK_CELL_LAYOUT (cellview));
 
   if (cellview->priv->model)
-     g_object_unref (cellview->priv->model);
+     g_object_unref_and_context (cellview->priv->model);
 
   if (cellview->priv->displayed_row)
      gtk_tree_row_reference_free (cellview->priv->displayed_row);
@@ -574,7 +574,7 @@ gtk_cell_view_cell_layout_pack_start (Gt
 
   g_object_ref_sink (renderer);
 
-  info = g_new0 (GtkCellViewCellInfo, 1);
+  info = g_slice_new0 (GtkCellViewCellInfo);
   info->cell = renderer;
   info->expand = expand ? TRUE : FALSE;
   info->pack = GTK_PACK_START;
@@ -596,7 +596,7 @@ gtk_cell_view_cell_layout_pack_end (GtkC
 
   g_object_ref_sink (renderer);
 
-  info = g_new0 (GtkCellViewCellInfo, 1);
+  info = g_slice_new0 (GtkCellViewCellInfo);
   info->cell = renderer;
   info->expand = expand ? TRUE : FALSE;
   info->pack = GTK_PACK_END;
@@ -636,7 +636,7 @@ gtk_cell_view_cell_layout_clear (GtkCell
 
       gtk_cell_view_cell_layout_clear_attributes (layout, info->cell);
       g_object_unref (info->cell);
-      g_free (info);
+      g_slice_free (GtkCellViewCellInfo, info);
       cellview->priv->cell_list = g_list_delete_link (cellview->priv->cell_list, 
 						      cellview->priv->cell_list);
     }
@@ -894,14 +894,14 @@ gtk_cell_view_set_model (GtkCellView  *c
         gtk_tree_row_reference_free (cell_view->priv->displayed_row);
       cell_view->priv->displayed_row = NULL;
 
-      g_object_unref (cell_view->priv->model);
+      g_object_unref_and_context (cell_view->priv->model);
       cell_view->priv->model = NULL;
     }
 
   cell_view->priv->model = model;
 
   if (cell_view->priv->model)
-    g_object_ref (cell_view->priv->model);
+    g_object_ref_and_context (cell_view->priv->model);
 }
 
 /**
Index: gtk/gtkclipboard.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkclipboard.c,v
retrieving revision 1.51
diff -u -p -r1.51 gtkclipboard.c
--- gtk/gtkclipboard.c	29 Jun 2006 09:18:05 -0000	1.51
+++ gtk/gtkclipboard.c	19 Jul 2006 22:41:01 -0000
@@ -228,7 +228,7 @@ clipboard_display_closed (GdkDisplay   *
   g_object_run_dispose (G_OBJECT (clipboard));
   clipboards = g_slist_remove (clipboards, clipboard);
   g_object_set_data (G_OBJECT (display), I_("gtk-clipboard-list"), clipboards);
-  g_object_unref (clipboard);
+  g_object_unref_with_context (clipboard, clipboard);
 }
 
 /**
@@ -355,6 +355,14 @@ make_clipboard_widget (GdkDisplay *displ
   return widget;
 }
 
+static void
+remove_clipboard_widget (GdkDisplay *display)
+{
+  GtkWidget *clip_widget = g_object_steal_data (G_OBJECT (display), "gtk-clipboard-widget");
+  if (clip_widget)
+    gtk_widget_destroy (clip_widget);
+}
+
 static GtkWidget *
 get_clipboard_widget (GdkDisplay *display)
 {
@@ -362,6 +370,8 @@ get_clipboard_widget (GdkDisplay *displa
   if (!clip_widget)
     {
       clip_widget = make_clipboard_widget (display, TRUE);
+      g_signal_connect (display, "closed",
+	  G_CALLBACK (remove_clipboard_widget), NULL);
       g_object_set_data (G_OBJECT (display), I_("gtk-clipboard-widget"), clip_widget);
     }
 
@@ -855,7 +865,7 @@ selection_received (GtkWidget           
 			  selection_data,
 			  request_info->user_data);
 
-  g_free (request_info);
+  g_slice_free (RequestContentsInfo, request_info);
 
   if (widget != get_clipboard_widget (gtk_widget_get_display (widget)))
     gtk_widget_destroy (widget);
@@ -897,7 +907,7 @@ gtk_clipboard_request_contents (GtkClipb
   else
     widget = clipboard_widget;
 
-  info = g_new (RequestContentsInfo, 1);
+  info = g_slice_new (RequestContentsInfo);
   info->callback = callback;
   info->user_data = user_data;
 
Index: gtk/gtkclist.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkclist.c,v
retrieving revision 1.240
diff -u -p -r1.240 gtkclist.c
--- gtk/gtkclist.c	21 Dec 2005 21:05:22 -0000	1.240
+++ gtk/gtkclist.c	19 Jul 2006 22:41:08 -0000
@@ -3289,14 +3289,14 @@ gtk_clist_set_cell_style (GtkCList *clis
     {
       if (GTK_WIDGET_REALIZED (clist))
         gtk_style_detach (clist_row->cell[column].style);
-      g_object_unref (clist_row->cell[column].style);
+      g_object_unref_and_context (clist_row->cell[column].style);
     }
 
   clist_row->cell[column].style = style;
 
   if (clist_row->cell[column].style)
     {
-      g_object_ref (clist_row->cell[column].style);
+      g_object_ref_and_context (clist_row->cell[column].style);
       
       if (GTK_WIDGET_REALIZED (clist))
         clist_row->cell[column].style =
@@ -3368,14 +3368,14 @@ gtk_clist_set_row_style (GtkCList *clist
     {
       if (GTK_WIDGET_REALIZED (clist))
         gtk_style_detach (clist_row->style);
-      g_object_unref (clist_row->style);
+      g_object_unref_and_context (clist_row->style);
     }
 
   clist_row->style = style;
 
   if (clist_row->style)
     {
-      g_object_ref (clist_row->style);
+      g_object_ref_and_context (clist_row->style);
       
       if (GTK_WIDGET_REALIZED (clist))
         clist_row->style = gtk_style_attach (clist_row->style,
Index: gtk/gtkcolorsel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcolorsel.c,v
retrieving revision 1.147
diff -u -p -r1.147 gtkcolorsel.c
--- gtk/gtkcolorsel.c	25 May 2006 05:30:14 -0000	1.147
+++ gtk/gtkcolorsel.c	19 Jul 2006 22:41:10 -0000
@@ -792,6 +792,7 @@ palette_change_color (GtkWidget         
   gdk_color.red = UNSCALE (color[0]);
   gdk_color.green = UNSCALE (color[1]);
   gdk_color.blue = UNSCALE (color[2]);
+   gdk_color.pixel = 0;
 
   x = 0;
   y = 0;			/* Quiet GCC */
@@ -1751,7 +1752,7 @@ update_color (GtkColorSelection *colorse
   gtk_entry_set_text (GTK_ENTRY (priv->hex_entry), entryval);
   priv->changing = FALSE;
 
-  g_object_ref (colorsel);
+  g_object_ref_and_context (colorsel);
   
   g_signal_emit (colorsel, color_selection_signals[COLOR_CHANGED], 0);
   
@@ -1760,7 +1761,7 @@ update_color (GtkColorSelection *colorse
   g_object_notify (G_OBJECT (colorsel), "current-alpha");
   g_object_thaw_notify (G_OBJECT (colorsel));
   
-  g_object_unref (colorsel);
+  g_object_unref_and_context (colorsel);
 }
 
 static void
Index: gtk/gtkcombo.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcombo.c,v
retrieving revision 1.99
diff -u -p -r1.99 gtkcombo.c
--- gtk/gtkcombo.c	6 Jul 2006 05:14:01 -0000	1.99
+++ gtk/gtkcombo.c	19 Jul 2006 22:41:11 -0000
@@ -191,7 +191,7 @@ gtk_combo_destroy (GtkObject *object)
   if (combo->popwin)
     {
       gtk_widget_destroy (combo->popwin);
-      g_object_unref (combo->popwin);
+      g_object_unref_and_context (combo->popwin);
       combo->popwin = NULL;
     }
 
@@ -561,7 +561,8 @@ gtk_combo_popup_list (GtkCombo *combo)
     {
       gtk_window_group_add_window (gtk_window_get_group (GTK_WINDOW (toplevel)), 
                                    GTK_WINDOW (combo->popwin));
-      gtk_window_set_transient_for (combo->popwin, GTK_WINDOW (toplevel));
+      gtk_window_set_transient_for (GTK_WINDOW(combo->popwin),
+				    GTK_WINDOW (toplevel));
     }
 
   gtk_widget_set_size_request (combo->popwin, width, height);
@@ -809,7 +810,7 @@ find_child_foreach (GtkWidget *widget,
 	  event->x < widget->allocation.x + widget->allocation.width &&
 	  event->y >= widget->allocation.y &&
 	  event->y < widget->allocation.y + widget->allocation.height)
-	event->window = g_object_ref (widget->window);
+	event->window = g_object_ref_with_context (widget->window, &event->window);
     }
 }
 
@@ -864,7 +865,7 @@ gtk_combo_list_enter (GtkWidget        *
 	  else
 	    child = combo->list;
 
-	  tmp_event->button.window = g_object_ref (child->window);
+	  tmp_event->button.window = g_object_ref_with_context (child->window, &tmp_event->button.window);
 	}
 
       gtk_widget_event (combo->list, tmp_event);
@@ -940,7 +941,7 @@ gtk_combo_init (GtkCombo * combo)
 
   combo->popwin = gtk_window_new (GTK_WINDOW_POPUP);
   gtk_window_set_type_hint (GTK_WINDOW (combo->popwin), GDK_WINDOW_TYPE_HINT_COMBO);
-  g_object_ref (combo->popwin);
+  g_object_ref_and_context (combo->popwin);
   gtk_window_set_resizable (GTK_WINDOW (combo->popwin), FALSE);
 
   g_signal_connect (combo->popwin, "key_press_event",
Index: gtk/gtkcombobox.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcombobox.c,v
retrieving revision 1.181
diff -u -p -r1.181 gtkcombobox.c
--- gtk/gtkcombobox.c	6 Jul 2006 05:14:01 -0000	1.181
+++ gtk/gtkcombobox.c	19 Jul 2006 22:41:17 -0000
@@ -1138,7 +1138,7 @@ gtk_combo_box_set_popup_widget (GtkCombo
     {
       gtk_container_remove (GTK_CONTAINER (combo_box->priv->popup_frame),
                             combo_box->priv->popup_widget);
-      g_object_unref (combo_box->priv->popup_widget);
+      g_object_unref_and_context (combo_box->priv->popup_widget);
       combo_box->priv->popup_widget = NULL;
     }
 
@@ -1224,7 +1224,7 @@ gtk_combo_box_set_popup_widget (GtkCombo
                          popup);
 
       gtk_widget_show (popup);
-      g_object_ref (popup);
+      g_object_ref_with_context (popup, &combo_box->priv->popup_widget);
       combo_box->priv->popup_widget = popup;
     }
 }
@@ -2099,7 +2099,7 @@ gtk_combo_box_unset_model (GtkComboBox *
 
   if (combo_box->priv->model)
     {
-      g_object_unref (combo_box->priv->model);
+      g_object_unref_and_context (combo_box->priv->model);
       combo_box->priv->model = NULL;
     }
 
@@ -4680,7 +4680,7 @@ gtk_combo_box_set_model (GtkComboBox  *c
     gtk_combo_box_unset_model (combo_box);
 
   combo_box->priv->model = model;
-  g_object_ref (combo_box->priv->model);
+  g_object_ref_and_context (combo_box->priv->model);
 
   combo_box->priv->inserted_id =
     g_signal_connect (combo_box->priv->model, "row_inserted",
@@ -5060,7 +5060,7 @@ popdown_idle (gpointer data)
   gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (combo_box));
   gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (combo_box));
 
-  g_object_unref (combo_box);
+  g_object_unref_with_context (combo_box, popdown_idle);
 
   GDK_THREADS_LEAVE ();
 
@@ -5071,7 +5071,7 @@ static void
 popdown_handler (GtkWidget *widget,
 		 gpointer   data)
 {
-  g_idle_add (popdown_idle, g_object_ref (data));
+  g_idle_add (popdown_idle, g_object_ref_with_context (data, popdown_idle));
 }
 
 static gboolean
Index: gtk/gtkcontainer.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkcontainer.c,v
retrieving revision 1.141
diff -u -p -r1.141 gtkcontainer.c
--- gtk/gtkcontainer.c	14 Dec 2005 19:39:44 -0000	1.141
+++ gtk/gtkcontainer.c	19 Jul 2006 22:41:19 -0000
@@ -359,8 +359,8 @@ gtk_container_child_get_valist (GtkConta
   g_return_if_fail (GTK_IS_WIDGET (child));
   g_return_if_fail (child->parent == GTK_WIDGET (container));
 
-  g_object_ref (container);
-  g_object_ref (child);
+  g_object_ref_and_context (container);
+  g_object_ref_and_context (child);
 
   name = first_property_name;
   while (name)
@@ -403,8 +403,8 @@ gtk_container_child_get_valist (GtkConta
       name = va_arg (var_args, gchar*);
     }
 
-  g_object_unref (child);
-  g_object_unref (container);
+  g_object_unref_and_context (child);
+  g_object_unref_and_context (container);
 }
 
 /**
@@ -430,8 +430,8 @@ gtk_container_child_get_property (GtkCon
   g_return_if_fail (property_name != NULL);
   g_return_if_fail (G_IS_VALUE (value));
   
-  g_object_ref (container);
-  g_object_ref (child);
+  g_object_ref_and_context (container);
+  g_object_ref_and_context (child);
   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
 				    G_OBJECT_TYPE (container), TRUE);
   if (!pspec)
@@ -461,8 +461,8 @@ gtk_container_child_get_property (GtkCon
 		     pspec->name,
 		     g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
 		     G_VALUE_TYPE_NAME (value));
-	  g_object_unref (child);
-	  g_object_unref (container);
+	  g_object_unref_and_context (child);
+	  g_object_unref_and_context (container);
 	  return;
 	}
       else
@@ -477,8 +477,8 @@ gtk_container_child_get_property (GtkCon
 	  g_value_unset (&tmp_value);
 	}
     }
-  g_object_unref (child);
-  g_object_unref (container);
+  g_object_unref_and_context (child);
+  g_object_unref_and_context (container);
 }
 
 /**
@@ -504,8 +504,8 @@ gtk_container_child_set_valist (GtkConta
   g_return_if_fail (GTK_IS_WIDGET (child));
   g_return_if_fail (child->parent == GTK_WIDGET (container));
 
-  g_object_ref (container);
-  g_object_ref (child);
+  g_object_ref_and_context (container);
+  g_object_ref_and_context (child);
 
   nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
   name = first_property_name;
@@ -551,8 +551,8 @@ gtk_container_child_set_valist (GtkConta
     }
   g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
 
-  g_object_unref (container);
-  g_object_unref (child);
+  g_object_unref_and_context (child);
+  g_object_unref_and_context (container);
 }
 
 /**
@@ -579,8 +579,8 @@ gtk_container_child_set_property (GtkCon
   g_return_if_fail (property_name != NULL);
   g_return_if_fail (G_IS_VALUE (value));
   
-  g_object_ref (container);
-  g_object_ref (child);
+  g_object_ref_and_context (container);
+  g_object_ref_and_context (child);
 
   nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
@@ -600,8 +600,8 @@ gtk_container_child_set_property (GtkCon
       container_set_child_property (container, child, pspec, value, nqueue);
     }
   g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
-  g_object_unref (container);
-  g_object_unref (child);
+  g_object_unref_and_context (child);
+  g_object_unref_and_context (container);
 }
 
 /**
@@ -625,8 +625,8 @@ gtk_container_add_with_properties (GtkCo
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (widget->parent == NULL);
 
-  g_object_ref (container);
-  g_object_ref (widget);
+  g_object_ref_and_context (container);
+  g_object_ref_and_context (widget);
   gtk_widget_freeze_child_notify (widget);
 
   g_signal_emit (container, container_signals[ADD], 0, widget);
@@ -640,8 +640,8 @@ gtk_container_add_with_properties (GtkCo
     }
 
   gtk_widget_thaw_child_notify (widget);
-  g_object_unref (widget);
-  g_object_unref (container);
+  g_object_unref_and_context (widget);
+  g_object_unref_and_context (container);
 }
 
 /**
@@ -823,6 +823,9 @@ gtk_container_destroy (GtkObject *object
     gtk_container_unset_focus_chain (container);
   
   gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
+
+   if (container->focus_child)
+     g_object_unref_and_context (container->focus_child);
   
   if (GTK_OBJECT_CLASS (parent_class)->destroy)
     (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
@@ -1462,10 +1465,10 @@ gtk_container_real_set_focus_child (GtkC
   if (child != container->focus_child)
     {
       if (container->focus_child)
-	g_object_unref (container->focus_child);
+	g_object_unref_and_context (container->focus_child);
       container->focus_child = child;
       if (container->focus_child)
-	g_object_ref (container->focus_child);
+	g_object_ref_and_context (container->focus_child);
     }
 
 
@@ -2205,6 +2208,11 @@ gtk_container_unset_focus_chain (GtkCont
     }
 }
 
+static void
+vadjustment_unref (gpointer adj)
+{
+   g_object_unref_with_context (adj, gtk_container_set_focus_vadjustment);
+}
 /**
  * gtk_container_set_focus_vadjustment:
  * @container: a #GtkContainer
@@ -2229,12 +2237,12 @@ gtk_container_set_focus_vadjustment (Gtk
     g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
 
   if (adjustment)
-    g_object_ref (adjustment);
+    g_object_ref_with_context (adjustment, gtk_container_set_focus_vadjustment);
 
   g_object_set_qdata_full (G_OBJECT (container),
 			   vadjustment_key_id,
 			   adjustment,
-			   g_object_unref);
+			   vadjustment_unref);
 }
 
 /**
@@ -2259,6 +2267,11 @@ gtk_container_get_focus_vadjustment (Gtk
   return vadjustment;
 }
 
+static void
+hadjustment_unref (gpointer adj)
+{
+   g_object_unref_with_context (adj, gtk_container_set_focus_hadjustment);
+}
 /**
  * gtk_container_set_focus_hadjustment:
  * @container: a #GtkContainer
@@ -2283,12 +2296,12 @@ gtk_container_set_focus_hadjustment (Gtk
     g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
 
   if (adjustment)
-    g_object_ref (adjustment);
+    g_object_ref_with_context (adjustment, gtk_container_set_focus_hadjustment);
 
   g_object_set_qdata_full (G_OBJECT (container),
 			   hadjustment_key_id,
 			   adjustment,
-			   g_object_unref);
+			   hadjustment_unref);
 }
 
 /**
@@ -2452,7 +2465,7 @@ gtk_container_propagate_expose (GtkConta
     {
       child_event = gdk_event_new (GDK_EXPOSE);
       child_event->expose = *event;
-      g_object_ref (child_event->expose.window);
+      g_object_ref_and_context (child_event->expose.window);
 
       child_event->expose.region = gtk_widget_region_intersect (child, event->region);
       if (!gdk_region_empty (child_event->expose.region))
Index: gtk/gtkctree.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkctree.c,v
retrieving revision 1.120
diff -u -p -r1.120 gtkctree.c
--- gtk/gtkctree.c	27 Dec 2005 23:46:28 -0000	1.120
+++ gtk/gtkctree.c	19 Jul 2006 22:41:24 -0000
@@ -4982,14 +4982,14 @@ gtk_ctree_node_set_cell_style (GtkCTree 
     {
       if (GTK_WIDGET_REALIZED (ctree))
         gtk_style_detach (GTK_CTREE_ROW (node)->row.cell[column].style);
-      g_object_unref (GTK_CTREE_ROW (node)->row.cell[column].style);
+      g_object_unref_and_context (GTK_CTREE_ROW (node)->row.cell[column].style);
     }
 
   GTK_CTREE_ROW (node)->row.cell[column].style = style;
 
   if (GTK_CTREE_ROW (node)->row.cell[column].style)
     {
-      g_object_ref (GTK_CTREE_ROW (node)->row.cell[column].style);
+      g_object_ref_and_context (GTK_CTREE_ROW (node)->row.cell[column].style);
       
       if (GTK_WIDGET_REALIZED (ctree))
         GTK_CTREE_ROW (node)->row.cell[column].style =
@@ -5054,14 +5054,14 @@ gtk_ctree_node_set_row_style (GtkCTree  
     {
       if (GTK_WIDGET_REALIZED (ctree))
         gtk_style_detach (GTK_CTREE_ROW (node)->row.style);
-      g_object_unref (GTK_CTREE_ROW (node)->row.style);
+      g_object_unref_and_context (GTK_CTREE_ROW (node)->row.style);
     }
 
   GTK_CTREE_ROW (node)->row.style = style;
 
   if (GTK_CTREE_ROW (node)->row.style)
     {
-      g_object_ref (GTK_CTREE_ROW (node)->row.style);
+      g_object_ref_and_context (GTK_CTREE_ROW (node)->row.style);
       
       if (GTK_WIDGET_REALIZED (ctree))
         GTK_CTREE_ROW (node)->row.style =
Index: gtk/gtkdialog.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdialog.c,v
retrieving revision 1.82
diff -u -p -r1.82 gtkdialog.c
--- gtk/gtkdialog.c	6 Jul 2006 05:14:01 -0000	1.82
+++ gtk/gtkdialog.c	19 Jul 2006 22:41:26 -0000
@@ -394,7 +394,7 @@ gtk_dialog_close (GtkDialog *dialog)
 
   event = gdk_event_new (GDK_DELETE);
   
-  event->any.window = g_object_ref (widget->window);
+  event->any.window = g_object_ref_with_context (widget->window, &event->any.window);
   event->any.send_event = TRUE;
   
   gtk_main_do_event (event);
@@ -957,7 +957,7 @@ gtk_dialog_run (GtkDialog *dialog)
   
   g_return_val_if_fail (GTK_IS_DIALOG (dialog), -1);
 
-  g_object_ref (dialog);
+  g_object_ref_and_context (dialog);
 
   was_modal = GTK_WINDOW (dialog)->modal;
   if (!was_modal)
@@ -1011,7 +1011,7 @@ gtk_dialog_run (GtkDialog *dialog)
       g_signal_handler_disconnect (dialog, destroy_handler);
     }
 
-  g_object_unref (dialog);
+  g_object_unref_and_context (dialog);
 
   return ri.response_id;
 }
Index: gtk/gtkdnd.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdnd.c,v
retrieving revision 1.155
diff -u -p -r1.155 gtkdnd.c
--- gtk/gtkdnd.c	18 Jul 2006 22:16:44 -0000	1.155
+++ gtk/gtkdnd.c	19 Jul 2006 22:41:29 -0000
@@ -389,6 +389,14 @@ gtk_drag_get_ipc_widget (GtkWidget *widg
   return result;
 }
 
+static void
+gtk_drag_destroy_ipc_widgets (GdkScreen *screen)
+{
+  GSList *widgets = g_object_steal_data (G_OBJECT (screen),
+      "gtk-dnd-ipc-widgets");
+  g_slist_foreach (widgets, (GFunc)gtk_widget_destroy, NULL);
+  g_slist_free (widgets);
+}
 
 /***************************************************************
  * gtk_drag_release_ipc_widget:
@@ -405,8 +413,14 @@ gtk_drag_release_ipc_widget (GtkWidget *
   GdkScreen *screen = gtk_widget_get_screen (widget);
   GSList *drag_widgets = g_object_get_data (G_OBJECT (screen),
 					    "gtk-dnd-ipc-widgets");
+
   if (window->group)
     gtk_window_group_remove_window (window->group, window);
+
+  if (!drag_widgets)
+    g_signal_connect (screen, "closed",
+	G_CALLBACK (gtk_drag_destroy_ipc_widgets), NULL);
+
   drag_widgets = g_slist_prepend (drag_widgets, widget);
   g_object_set_data (G_OBJECT (screen),
 		     I_("gtk-dnd-ipc-widgets"),
@@ -838,10 +852,11 @@ gtk_drag_get_data (GtkWidget      *widge
   g_object_ref (context);
   g_object_ref (widget);
   
-  g_signal_connect (selection_widget, "selection_received",
+  g_signal_connect (selection_widget, "selection-received",
 		    G_CALLBACK (gtk_drag_selection_received), widget);
 
-  g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
+  g_object_set_data_full (G_OBJECT (selection_widget),
+      I_("drag-context"), context, g_object_unref);
 
   gtk_selection_convert (selection_widget,
 			 gdk_drag_get_selection (context),
@@ -927,8 +942,9 @@ gtk_drag_finish (GdkDragContext *context
 
       g_object_ref (context);
       
-      g_object_set_data (G_OBJECT (selection_widget), I_("drag-context"), context);
-      g_signal_connect (selection_widget, "selection_received",
+      g_object_set_data_full (G_OBJECT (selection_widget),
+	  I_("drag-context"), context, g_object_unref);
+      g_signal_connect (selection_widget, "selection-received",
 			G_CALLBACK (gtk_drag_selection_received),
 			NULL);
       
@@ -1140,8 +1156,8 @@ gtk_drag_dest_set_proxy (GtkWidget      
   site->target_list = NULL;
   site->actions = 0;
   site->proxy_window = proxy_window;
-  if (proxy_window)
-    g_object_ref (proxy_window);
+  if (site->proxy_window)
+    g_object_ref_and_context (site->proxy_window);
   site->do_proxy = TRUE;
   site->proxy_protocol = protocol;
   site->proxy_coords = use_coordinates;
@@ -1615,7 +1631,6 @@ gtk_drag_selection_received (GtkWidget  
 					data);
   
   g_object_set_data (G_OBJECT (widget), I_("drag-context"), NULL);
-  g_object_unref (context);
 
   gtk_drag_release_ipc_widget (widget);
 }
@@ -1903,7 +1918,7 @@ gtk_drag_dest_site_destroy (gpointer dat
   GtkDragDestSite *site = data;
 
   if (site->proxy_window)
-    g_object_unref (site->proxy_window);
+    g_object_unref_and_context (site->proxy_window);
     
   if (site->target_list)
     gtk_target_list_unref (site->target_list);
@@ -2618,9 +2633,9 @@ gtk_drag_source_unset_icon (GtkDragSourc
       break;
     case GTK_IMAGE_PIXMAP:
       if (site->icon_data.pixmap.pixmap)
-	g_object_unref (site->icon_data.pixmap.pixmap);
+	g_object_unref_and_context (site->icon_data.pixmap.pixmap);
       if (site->icon_mask)
-	g_object_unref (site->icon_mask);
+	g_object_unref_and_context (site->icon_mask);
       break;
     case GTK_IMAGE_PIXBUF:
       g_object_unref (site->icon_data.pixbuf.pixbuf);
@@ -2638,7 +2653,7 @@ gtk_drag_source_unset_icon (GtkDragSourc
   site->icon_type = GTK_IMAGE_EMPTY;
   
   if (site->colormap)
-    g_object_unref (site->colormap);
+    g_object_unref_and_context (site->colormap);
   site->colormap = NULL;
 }
 
@@ -2670,10 +2685,10 @@ gtk_drag_source_set_icon (GtkWidget     
   site = g_object_get_data (G_OBJECT (widget), "gtk-site-data");
   g_return_if_fail (site != NULL);
   
-  g_object_ref (colormap);
-  g_object_ref (pixmap);
+  g_object_ref_with_context (colormap, &site->colormap);
+  g_object_ref_with_context (pixmap, &site->icon_data.pixmap.pixmap);
   if (mask)
-    g_object_ref (mask);
+    g_object_ref_with_context (mask, &site->icon_mask);
 
   gtk_drag_source_unset_icon (site);
 
@@ -3232,21 +3247,21 @@ gtk_drag_set_default_icon (GdkColormap  
   g_return_if_fail (!mask || GDK_IS_PIXMAP (mask));
   
   if (default_icon_colormap)
-    g_object_unref (default_icon_colormap);
+    g_object_unref_and_context (default_icon_colormap);
   if (default_icon_pixmap)
-    g_object_unref (default_icon_pixmap);
+    g_object_unref_and_context (default_icon_pixmap);
   if (default_icon_mask)
-    g_object_unref (default_icon_mask);
+    g_object_unref_and_context (default_icon_mask);
 
   default_icon_colormap = colormap;
-  g_object_ref (colormap);
+  g_object_ref_with_context (colormap, &default_icon_colormap);
   
   default_icon_pixmap = pixmap;
-  g_object_ref (pixmap);
+  g_object_ref_with_context (pixmap, &default_icon_pixmap);
 
   default_icon_mask = mask;
   if (mask)
-    g_object_ref (mask);
+    g_object_ref_with_context (mask, &default_icon_mask);
   
   default_icon_hot_x = hot_x;
   default_icon_hot_y = hot_y;
@@ -3944,7 +3959,7 @@ gtk_drag_end (GtkDragSourceInfo *info, g
    */
 
   send_event = gdk_event_new (GDK_BUTTON_RELEASE);
-  send_event->button.window = g_object_ref (gtk_widget_get_root_window (source_widget));
+  send_event->button.window = g_object_ref_with_context (gtk_widget_get_root_window (source_widget), &send_event->button.window);
   send_event->button.send_event = TRUE;
   send_event->button.time = time;
   send_event->button.x = 0;
Index: gtk/gtkdrawingarea.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdrawingarea.c,v
retrieving revision 1.26
diff -u -p -r1.26 gtkdrawingarea.c
--- gtk/gtkdrawingarea.c	14 May 2006 04:25:28 -0000	1.26
+++ gtk/gtkdrawingarea.c	19 Jul 2006 22:41:29 -0000
@@ -132,7 +132,7 @@ gtk_drawing_area_send_configure (GtkDraw
 
   widget = GTK_WIDGET (darea);
 
-  event->configure.window = g_object_ref (widget->window);
+  event->configure.window = g_object_ref_with_context (widget->window, &event->configure.window);
   event->configure.send_event = TRUE;
   event->configure.x = widget->allocation.x;
   event->configure.y = widget->allocation.y;
Index: gtk/gtkentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentry.c,v
retrieving revision 1.317
diff -u -p -r1.317 gtkentry.c
--- gtk/gtkentry.c	29 Jun 2006 09:18:05 -0000	1.317
+++ gtk/gtkentry.c	19 Jul 2006 22:41:35 -0000
@@ -1142,9 +1142,9 @@ gtk_entry_finalize (GObject *object)
   gtk_entry_set_completion (entry, NULL);
 
   if (entry->cached_layout)
-    g_object_unref (entry->cached_layout);
+    g_object_unref_with_context (entry->cached_layout, entry->cached_layout);
 
-  g_object_unref (entry->im_context);
+  g_object_unref_with_context (entry->im_context, entry->im_context);
 
   if (entry->blink_timeout)
     g_source_remove (entry->blink_timeout);
@@ -2117,7 +2117,7 @@ gtk_entry_insert_text (GtkEditable *edit
   if (*position < 0 || *position > entry->text_length)
     *position = entry->text_length;
   
-  g_object_ref (editable);
+  g_object_ref_and_context (editable);
   
   if (new_text_length <= 63)
     text = buf;
@@ -2135,7 +2135,7 @@ gtk_entry_insert_text (GtkEditable *edit
   if (new_text_length > 63)
     g_free (text);
 
-  g_object_unref (editable);
+  g_object_unref_and_context (editable);
 }
 
 static void
@@ -2152,11 +2152,11 @@ gtk_entry_delete_text (GtkEditable *edit
   if (start_pos > end_pos)
     start_pos = end_pos;
   
-  g_object_ref (editable);
+  g_object_ref_and_context (editable);
 
   g_signal_emit_by_name (editable, "delete_text", start_pos, end_pos);
 
-  g_object_unref (editable);
+  g_object_unref_and_context (editable);
 }
 
 static gchar *    
@@ -2978,7 +2978,7 @@ gtk_entry_reset_layout (GtkEntry *entry)
 {
   if (entry->cached_layout)
     {
-      g_object_unref (entry->cached_layout);
+      g_object_unref_with_context (entry->cached_layout, entry->cached_layout);
       entry->cached_layout = NULL;
     }
 }
@@ -3976,14 +3976,14 @@ paste_received (GtkClipboard *clipboard,
 	g_signal_handler_unblock (entry, completion->priv->changed_id);
     }
 
-  g_object_unref (entry);
+  g_object_unref_with_context (entry, paste_received);
 }
 
 static void
 gtk_entry_paste (GtkEntry *entry,
 		 GdkAtom   selection)
 {
-  g_object_ref (entry);
+  g_object_ref_with_context (entry, paste_received);
   gtk_clipboard_request_text (gtk_widget_get_clipboard (GTK_WIDGET (entry), selection),
 			      paste_received, entry);
 }
@@ -4956,21 +4956,21 @@ popup_targets_received (GtkClipboard    
 	}
     }
 
-  g_object_unref (entry);
-  g_free (info);
+  g_object_unref_with_context (entry, popup_targets_received);
+  g_slice_free (PopupInfo, info);
 }
 			
 static void
 gtk_entry_do_popup (GtkEntry       *entry,
                     GdkEventButton *event)
 {
-  PopupInfo *info = g_new (PopupInfo, 1);
+  PopupInfo *info = g_slice_new (PopupInfo);
 
   /* In order to know what entries we should make sensitive, we
    * ask for the current targets of the clipboard, and when
    * we get them, then we actually pop up the menu.
    */
-  info->entry = g_object_ref (entry);
+  info->entry = g_object_ref_with_context (entry, popup_targets_received);
   
   if (event)
     {
Index: gtk/gtkentrycompletion.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkentrycompletion.c,v
retrieving revision 1.79
diff -u -p -r1.79 gtkentrycompletion.c
--- gtk/gtkentrycompletion.c	17 Jul 2006 03:59:17 -0000	1.79
+++ gtk/gtkentrycompletion.c	19 Jul 2006 22:41:37 -0000
@@ -407,6 +407,7 @@ gtk_entry_completion_init (GtkEntryCompl
 
   priv->action_view =
     gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->actions));
+  g_object_ref_sink_and_context (priv->action_view);
   g_signal_connect (priv->action_view, "button_press_event",
                     G_CALLBACK (gtk_entry_completion_action_button_press),
                     completion);
@@ -467,7 +468,7 @@ gtk_entry_completion_set_property (GObje
                                    GParamSpec   *pspec)
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
-  GtkEntryCompletionPrivate *priv = GTK_ENTRY_COMPLETION_GET_PRIVATE (completion);
+  GtkEntryCompletionPrivate *priv = completion->priv;
 
   switch (prop_id)
     {
@@ -556,24 +557,27 @@ static void
 gtk_entry_completion_finalize (GObject *object)
 {
   GtkEntryCompletion *completion = GTK_ENTRY_COMPLETION (object);
+  GtkEntryCompletionPrivate *priv = completion->priv;
 
-  if (completion->priv->tree_view)
-    gtk_widget_destroy (completion->priv->tree_view);
+  if (priv->tree_view)
+    gtk_widget_destroy (priv->tree_view);
 
-  if (completion->priv->entry)
-    gtk_entry_set_completion (GTK_ENTRY (completion->priv->entry), NULL);
+  if (priv->entry)
+    gtk_entry_set_completion (GTK_ENTRY (priv->entry), NULL);
 
-  if (completion->priv->actions)
-    g_object_unref (completion->priv->actions);
+  if (priv->actions)
+    g_object_unref_with_context (priv->actions, priv->actions);
+  if (priv->action_view)
+    g_object_unref_and_context (priv->action_view);
 
-  if (completion->priv->case_normalized_key)
-    g_free (completion->priv->case_normalized_key);
+  if (priv->case_normalized_key)
+    g_free (priv->case_normalized_key);
 
-  if (completion->priv->popup_window)
-    gtk_widget_destroy (completion->priv->popup_window);
+  if (priv->popup_window)
+    gtk_widget_destroy (priv->popup_window);
 
-  if (completion->priv->match_notify)
-    (* completion->priv->match_notify) (completion->priv->match_data);
+  if (priv->match_notify)
+    (* priv->match_notify) (priv->match_data);
 
   G_OBJECT_CLASS (gtk_entry_completion_parent_class)->finalize (object);
 }
Index: gtk/gtkeventbox.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkeventbox.c,v
retrieving revision 1.40
diff -u -p -r1.40 gtkeventbox.c
--- gtk/gtkeventbox.c	14 May 2006 04:25:29 -0000	1.40
+++ gtk/gtkeventbox.c	19 Jul 2006 22:41:37 -0000
@@ -414,7 +414,7 @@ gtk_event_box_realize (GtkWidget *widget
   else
     {
       widget->window = gtk_widget_get_parent_window (widget);
-      g_object_ref (widget->window);
+      g_object_ref_and_context (widget->window);
     }
 
   if (!visible_window || priv->above_child)
Index: gtk/gtkexpander.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkexpander.c,v
retrieving revision 1.28
diff -u -p -r1.28 gtkexpander.c
--- gtk/gtkexpander.c	14 May 2006 04:25:29 -0000	1.28
+++ gtk/gtkexpander.c	19 Jul 2006 22:41:39 -0000
@@ -393,7 +393,7 @@ gtk_expander_realize (GtkWidget *widget)
   attributes_mask = GDK_WA_X | GDK_WA_Y;
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
 
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
 				       &attributes, attributes_mask);
Index: gtk/gtkfilechooserbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserbutton.c,v
retrieving revision 1.51
diff -u -p -r1.51 gtkfilechooserbutton.c
--- gtk/gtkfilechooserbutton.c	10 Jul 2006 16:51:52 -0000	1.51
+++ gtk/gtkfilechooserbutton.c	19 Jul 2006 22:41:41 -0000
@@ -690,7 +690,7 @@ gtk_file_chooser_button_constructor (GTy
 			     (gpointer *) (&priv->dialog));
 
   priv->fs =
-    g_object_ref (_gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (priv->dialog)));
+    g_object_ref_with_context (_gtk_file_chooser_get_file_system (GTK_FILE_CHOOSER (priv->dialog)), &priv->fs);
 
   model_add_special (button);
 
@@ -903,12 +903,14 @@ gtk_file_chooser_button_destroy (GtkObje
   if (priv->dnd_select_folder_handle)
     {
       gtk_file_system_cancel_operation (priv->dnd_select_folder_handle);
+      g_object_unref_with_context (priv->dnd_select_folder_handle, priv->dnd_select_folder_handle);
       priv->dnd_select_folder_handle = NULL;
     }
 
   if (priv->update_button_handle)
     {
       gtk_file_system_cancel_operation (priv->update_button_handle);
+      g_object_unref_with_context (priv->update_button_handle, priv->update_button_handle);
       priv->update_button_handle = NULL;
     }
 
@@ -918,6 +920,7 @@ gtk_file_chooser_button_destroy (GtkObje
         {
           GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
           gtk_file_system_cancel_operation (handle);
+	  g_object_unref_with_context (handle, handle);
         }
       g_slist_free (priv->change_icon_theme_handles);
       priv->change_icon_theme_handles = NULL;
@@ -925,13 +928,13 @@ gtk_file_chooser_button_destroy (GtkObje
 
   if (priv->model)
     {
-      g_object_unref (priv->model);
+      g_object_unref_with_context (priv->model, priv->model);
       priv->model = NULL;
     }
 
   if (priv->filter_model)
     {
-      g_object_unref (priv->filter_model);
+      g_object_unref_with_context (priv->filter_model, priv->filter_model);
       priv->filter_model = NULL;
     }
 
@@ -939,7 +942,7 @@ gtk_file_chooser_button_destroy (GtkObje
     {
       g_signal_handler_disconnect (priv->fs, priv->fs_volumes_changed_id);
       g_signal_handler_disconnect (priv->fs, priv->fs_bookmarks_changed_id);
-      g_object_unref (priv->fs);
+      g_object_unref_and_context (priv->fs);
       priv->fs = NULL;
     }
 
@@ -973,15 +976,14 @@ dnd_select_folder_get_info_cb (GtkFileSy
 
   if (handle != data->button->priv->dnd_select_folder_handle)
     {
-      g_object_unref (data->button);
+      g_object_unref_and_context (data->button);
       gtk_file_path_free (data->path);
       g_strfreev (data->uris);
       g_free (data);
-
-      g_object_unref (handle);
       return;
     }
 
+  g_object_unref_with_context (handle, handle);
   data->button->priv->dnd_select_folder_handle = NULL;
 
   if (!cancelled && !error && info != NULL)
@@ -999,12 +1001,10 @@ dnd_select_folder_get_info_cb (GtkFileSy
 
   if (data->selected || data->uris[++data->i] == NULL)
     {
-      g_object_unref (data->button);
+      g_object_unref_and_context (data->button);
       gtk_file_path_free (data->path);
       g_strfreev (data->uris);
       g_free (data);
-
-      g_object_unref (handle);
       return;
     }
 
@@ -1018,8 +1018,6 @@ dnd_select_folder_get_info_cb (GtkFileSy
     gtk_file_system_get_info (handle->file_system, data->path,
 			      GTK_FILE_INFO_IS_FOLDER,
 			      dnd_select_folder_get_info_cb, user_data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -1059,7 +1057,7 @@ gtk_file_chooser_button_drag_data_receiv
 	  break;
 
 	info = g_new0 (struct DndSelectFolderData, 1);
-	info->button = g_object_ref (button);
+	info->button = g_object_ref_with_context (button, &info->button);
 	info->i = 0;
 	info->uris = uris;
 	info->selected = FALSE;
@@ -1069,7 +1067,10 @@ gtk_file_chooser_button_drag_data_receiv
 						  info->uris[info->i]);
 
 	if (priv->dnd_select_folder_handle)
-	  gtk_file_system_cancel_operation (priv->dnd_select_folder_handle);
+	  {
+	    gtk_file_system_cancel_operation (priv->dnd_select_folder_handle);
+	    g_object_unref_with_context (priv->dnd_select_folder_handle, priv->dnd_select_folder_handle);
+	  }
 
 	priv->dnd_select_folder_handle =
 	  gtk_file_system_get_info (priv->fs, info->path,
@@ -1196,6 +1197,7 @@ change_icon_theme_get_info_cb (GtkFileSy
 
   data->button->priv->change_icon_theme_handles =
     g_slist_remove (data->button->priv->change_icon_theme_handles, handle);
+  g_object_unref_with_context (handle, handle);
 
   if (cancelled || error)
     goto out;
@@ -1218,7 +1220,7 @@ change_icon_theme_get_info_cb (GtkFileSy
       gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
 			  ICON_COLUMN, pixbuf,
 			  -1);
-      g_object_unref (pixbuf);
+      g_object_unref_with_context (pixbuf, pixbuf);
 
       g_object_set (data->button->priv->icon_cell,
 		    "width", width,
@@ -1226,11 +1228,9 @@ change_icon_theme_get_info_cb (GtkFileSy
     }
 
 out:
-  g_object_unref (data->button);
+  g_object_unref_and_context (data->button);
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -1247,6 +1247,7 @@ change_icon_theme (GtkFileChooserButton 
     {
       GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
       gtk_file_system_cancel_operation (handle);
+      g_object_unref_with_context (handle, handle);
     }
   g_slist_free (button->priv->change_icon_theme_handles);
   button->priv->change_icon_theme_handles = NULL;
@@ -1290,7 +1291,7 @@ change_icon_theme (GtkFileChooserButton 
 	      struct ChangeIconThemeData *info;
 
 	      info = g_new0 (struct ChangeIconThemeData, 1);
-	      info->button = g_object_ref (button);
+	      info->button = g_object_ref_with_context (button, &info->button);
 	      path = gtk_tree_model_get_path (priv->model, &iter);
 	      info->row_ref = gtk_tree_row_reference_new (priv->model, path);
 	      gtk_tree_path_free (path);
@@ -1330,7 +1331,7 @@ change_icon_theme (GtkFileChooserButton 
 			  -1);
 
       if (pixbuf)
-	g_object_unref (pixbuf);
+	g_object_unref_with_context (pixbuf, pixbuf);
     }
   while (gtk_tree_model_iter_next (priv->model, &iter));
 
@@ -1415,6 +1416,7 @@ set_info_get_info_cb (GtkFileSystemHandl
   gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
 		      HANDLE_COLUMN, NULL,
 		      -1);
+  g_object_unref_with_context (model_handle, model_handle);
 
   if (cancelled || error)
     /* There was an error, leave the fallback name in there */
@@ -1430,14 +1432,12 @@ set_info_get_info_cb (GtkFileSystemHandl
 		      -1);
 
   if (pixbuf)
-    g_object_unref (pixbuf);
+    g_object_unref_with_context (pixbuf, pixbuf);
 
 out:
-  g_object_unref (data->button);
+  g_object_unref_and_context (data->button);
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -1450,7 +1450,7 @@ set_info_for_path_at_iter (GtkFileChoose
   GtkFileSystemHandle *handle;
 
   data = g_new0 (struct SetDisplayNameData, 1);
-  data->button = g_object_ref (button);
+  data->button = g_object_ref_with_context (button, &data->button);
 
   tree_path = gtk_tree_model_get_path (button->priv->model, iter);
   data->row_ref = gtk_tree_row_reference_new (button->priv->model, tree_path);
@@ -1582,6 +1582,7 @@ model_add_special_get_info_cb (GtkFileSy
   gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
 		      HANDLE_COLUMN, NULL,
 		      -1);
+  g_object_unref_with_context (model_handle, model_handle);
 
   if (cancelled || error)
     goto out;
@@ -1594,7 +1595,7 @@ model_add_special_get_info_cb (GtkFileSy
       gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
 			  ICON_COLUMN, pixbuf,
 			  -1);
-      g_object_unref (pixbuf);
+      g_object_unref_with_context (pixbuf, pixbuf);
     }
 
   gtk_list_store_set (GTK_LIST_STORE (data->button->priv->model), &iter,
@@ -1602,11 +1603,9 @@ model_add_special_get_info_cb (GtkFileSy
 		      -1);
 
 out:
-  g_object_unref (data->button);
+  g_object_unref_and_context (data->button);
   gtk_tree_row_reference_free (data->row_ref);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static inline void
@@ -1635,7 +1634,7 @@ model_add_special (GtkFileChooserButton 
       pos++;
 
       info = g_new0 (struct ChangeIconThemeData, 1);
-      info->button = g_object_ref (button);
+      info->button = g_object_ref_with_context (button, &info->button);
       tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
       info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
 						  tree_path);
@@ -1646,9 +1645,9 @@ model_add_special (GtkFileChooserButton 
 					 model_add_special_get_info_cb, info);
 
       gtk_list_store_set (store, &iter,
+			  TYPE_COLUMN, ROW_TYPE_SPECIAL,
 			  ICON_COLUMN, NULL,
 			  DISPLAY_NAME_COLUMN, NULL,
-			  TYPE_COLUMN, ROW_TYPE_SPECIAL,
 			  DATA_COLUMN, path,
 			  IS_FOLDER_COLUMN, TRUE,
 			  HANDLE_COLUMN, handle,
@@ -1677,7 +1676,7 @@ model_add_special (GtkFileChooserButton 
       pos++;
 
       info = g_new0 (struct ChangeIconThemeData, 1);
-      info->button = g_object_ref (button);
+      info->button = g_object_ref_with_context (button, &info->button);
       tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (store), &iter);
       info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (store),
 						  tree_path);
@@ -1693,6 +1692,7 @@ model_add_special (GtkFileChooserButton 
 			  DISPLAY_NAME_COLUMN, _(DESKTOP_DISPLAY_NAME),
 			  DATA_COLUMN, path,
 			  IS_FOLDER_COLUMN, TRUE,
+			  HANDLE_COLUMN, handle,
 			  -1);
 
       button->priv->n_special++;
@@ -1736,7 +1736,7 @@ model_add_volumes (GtkFileChooserButton 
 			  -1);
 
       if (pixbuf)
-	g_object_unref (pixbuf);
+	g_object_unref_with_context (pixbuf, pixbuf);
       g_free (display_name);
 
       button->priv->n_volumes++;
@@ -2109,6 +2109,7 @@ update_label_get_info_cb (GtkFileSystemH
   if (handle != priv->update_button_handle)
     goto out;
 
+  g_object_unref_with_context (handle, handle);
   priv->update_button_handle = NULL;
 
   if (cancelled || error)
@@ -2125,11 +2126,10 @@ update_label_get_info_cb (GtkFileSystemH
 
   gtk_image_set_from_pixbuf (GTK_IMAGE (priv->image), pixbuf);
   if (pixbuf)
-    g_object_unref (pixbuf);
+    g_object_unref_with_context (pixbuf, pixbuf);
 
 out:
-  g_object_unref (button);
-  g_object_unref (handle);
+  g_object_unref_with_context (button, &update_label_get_info_cb);
 }
 
 static void
@@ -2177,13 +2177,16 @@ update_label_and_image (GtkFileChooserBu
 	}
 
       if (priv->update_button_handle)
-	gtk_file_system_cancel_operation (priv->update_button_handle);
+	{
+	  gtk_file_system_cancel_operation (priv->update_button_handle);
+	  g_object_unref_with_context (priv->update_button_handle, priv->update_button_handle);
+	}
 
       priv->update_button_handle =
         gtk_file_system_get_info (priv->fs, path,
 				  GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_ICON,
 				  update_label_get_info_cb,
-				  g_object_ref (button));
+				  g_object_ref_with_context (button, &update_label_get_info_cb));
     }
 out:
   gtk_file_paths_free (paths);
Index: gtk/gtkfilechooserdefault.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserdefault.c,v
retrieving revision 1.328
diff -u -p -r1.328 gtkfilechooserdefault.c
--- gtk/gtkfilechooserdefault.c	18 Jul 2006 16:36:16 -0000	1.328
+++ gtk/gtkfilechooserdefault.c	19 Jul 2006 22:41:50 -0000
@@ -690,7 +690,10 @@ shortcuts_free_row_data (GtkFileChooserD
 		      -1);
 
   if (handle)
-    gtk_file_system_cancel_operation (handle);
+    {
+      gtk_file_system_cancel_operation (handle);
+      g_object_unref (handle);
+    }
 
   if (!col_data)
     return;
@@ -797,7 +800,7 @@ gtk_file_chooser_default_finalize (GObje
 
   shortcuts_free (impl);
 
-  g_object_unref (impl->file_system);
+  g_object_unref_with_context (impl->file_system, impl->file_system);
 
   g_free (impl->browse_files_last_selected_name);
 
@@ -1105,6 +1108,7 @@ shortcuts_reload_icons_get_info_cb (GtkF
     goto out;
 
   data->impl->reload_icon_handles = g_slist_remove (data->impl->reload_icon_handles, handle);
+  g_object_unref (handle);
 
   if (cancelled || error)
     goto out;
@@ -1124,10 +1128,8 @@ shortcuts_reload_icons_get_info_cb (GtkF
 
 out:
   gtk_tree_row_reference_free (data->row_ref);
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -1145,6 +1147,7 @@ shortcuts_reload_icons (GtkFileChooserDe
     {
       GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (l->data);
       gtk_file_system_cancel_operation (handle);
+      g_object_unref (handle);
     }
   g_slist_free (impl->reload_icon_handles);
   impl->reload_icon_handles = NULL;
@@ -1189,7 +1192,7 @@ shortcuts_reload_icons (GtkFileChooserDe
 	      path = data;
 
 	      info = g_new0 (struct ReloadIconsData, 1);
-	      info->impl = g_object_ref (impl);
+	      info->impl = g_object_ref_with_context (impl, &info->impl);
 	      tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL (impl->shortcuts_model), &iter);
 	      info->row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (impl->shortcuts_model), tree_path);
 	      gtk_tree_path_free (tree_path);
@@ -1358,6 +1361,7 @@ get_file_info_finished (GtkFileSystemHan
   gtk_list_store_set (request->impl->shortcuts_model, &iter,
 		      SHORTCUTS_COL_HANDLE, NULL,
 		      -1);
+  g_object_unref (handle);
 
   if (cancelled)
     goto out;
@@ -1422,14 +1426,12 @@ get_file_info_finished (GtkFileSystemHan
     g_object_unref (pixbuf);
 
 out:
-  g_object_unref (request->impl);
+  g_object_unref_and_context (request->impl);
   gtk_file_path_free (request->parent_path);
   gtk_file_path_free (request->path);
   gtk_tree_row_reference_free (request->row_ref);
   g_free (request->label_copy);
   g_free (request);
-
-  g_object_unref (handle);
 }
 
 /* Inserts a path in the shortcuts tree, making a copy of it; alternatively,
@@ -1466,7 +1468,7 @@ shortcuts_insert_path (GtkFileChooserDef
       GtkTreePath *p;
 
       request = g_new0 (struct ShortcutsInsertRequest, 1);
-      request->impl = g_object_ref (impl);
+      request->impl = g_object_ref_with_context (impl, &request->impl);
       request->path = gtk_file_path_copy (path);
       request->name_only = TRUE;
       request->removable = removable;
@@ -1911,6 +1913,8 @@ shortcuts_add_current_folder (GtkFileCho
 
       if (base_path)
 	gtk_file_path_free (base_path);
+      if (volume)
+	  gtk_file_system_volume_free (impl->file_system, volume);
     }
   else if (impl->save_folder_combo != NULL)
     gtk_combo_box_set_active (GTK_COMBO_BOX (impl->save_folder_combo), pos);
@@ -1967,7 +1971,7 @@ shortcuts_model_create (GtkFileChooserDe
 					      G_TYPE_BOOLEAN,   /* is the previous column a volume? */
 					      G_TYPE_BOOLEAN,   /* removable */
 					      G_TYPE_BOOLEAN,   /* pixbuf cell visibility */
-					      G_TYPE_OBJECT);   /* GtkFileSystemHandle */
+					      G_TYPE_POINTER);   /* GtkFileSystemHandle */
 
   if (impl->file_system)
     {
@@ -2029,6 +2033,7 @@ edited_idle_create_folder_cb (GtkFileSys
     goto out;
 
   impl->pending_handles = g_slist_remove (impl->pending_handles, handle);
+  g_object_unref (handle);
 
   if (cancelled)
     goto out;
@@ -2039,8 +2044,7 @@ edited_idle_create_folder_cb (GtkFileSys
     error_creating_folder_dialog (impl, path, g_error_copy (error));
 
  out:
-  g_object_unref (impl);
-  g_object_unref (handle);
+  g_object_unref_with_context (impl, edited_idle_create_folder_cb);
 }
 
 /* Idle handler for creating a new folder after editing its name cell, or for
@@ -2075,7 +2079,7 @@ edited_idle_cb (GtkFileChooserDefault *i
 
 	  handle = gtk_file_system_create_folder (impl->file_system, file_path,
 						  edited_idle_create_folder_cb,
-						  g_object_ref (impl));
+						  g_object_ref_with_context (impl, edited_idle_create_folder_cb));
 	  impl->pending_handles = g_slist_append (impl->pending_handles, handle);
 
 	  gtk_file_path_free (file_path);
@@ -3675,6 +3679,7 @@ file_list_drag_data_received_get_info_cb
     goto out;
 
   data->impl->file_list_drag_data_received_handle = NULL;
+  g_object_unref (handle);
 
   if (cancelled || error)
     goto out;
@@ -3700,12 +3705,10 @@ file_list_drag_data_received_get_info_cb
     file_list_drag_data_select_uris (data->impl, data->uris);
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   g_strfreev (data->uris);
   gtk_file_path_free (data->path);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -3740,12 +3743,15 @@ file_list_drag_data_received_cb (GtkWidg
 	  struct FileListDragData *data;
 
 	  data = g_new0 (struct FileListDragData, 1);
-	  data->impl = g_object_ref (impl);
+	  data->impl = g_object_ref_with_context (impl, &data->impl);
 	  data->uris = uris;
 	  data->path = path;
 
 	  if (impl->file_list_drag_data_received_handle)
-	    gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
+	    {
+	      gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
+	      g_object_unref (impl->file_list_drag_data_received_handle);
+	    }
 
 	  impl->file_list_drag_data_received_handle =
 	    gtk_file_system_get_info (impl->file_system, path,
@@ -4621,24 +4627,22 @@ static void
 set_extra_widget (GtkFileChooserDefault *impl,
 		  GtkWidget             *extra_widget)
 {
-  if (extra_widget)
-    {
-      g_object_ref (extra_widget);
-      /* FIXME: is this right ? */
-      gtk_widget_show (extra_widget);
-    }
+  if (extra_widget == impl->extra_widget)
+    return;
 
   if (impl->extra_widget)
     {
       gtk_container_remove (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
-      g_object_unref (impl->extra_widget);
+      g_object_unref_and_context (impl->extra_widget);
     }
 
   impl->extra_widget = extra_widget;
   if (impl->extra_widget)
     {
       gtk_container_add (GTK_CONTAINER (impl->extra_align), impl->extra_widget);
+      gtk_widget_show (impl->extra_widget); /* FIXME: is this right ? */
       gtk_widget_show (impl->extra_align);
+      g_object_ref_and_context (impl->extra_widget);
     }
   else
     gtk_widget_hide (impl->extra_align);
@@ -4734,7 +4738,7 @@ set_file_system_backend (GtkFileChooserD
       impl->volumes_changed_id = 0;
       g_signal_handler_disconnect (impl->file_system, impl->bookmarks_changed_id);
       impl->bookmarks_changed_id = 0;
-      g_object_unref (impl->file_system);
+      g_object_unref_with_context (impl->file_system, impl->file_system);
     }
 
   impl->file_system = NULL;
@@ -5057,6 +5061,7 @@ gtk_file_chooser_default_dispose (GObjec
         {
 	  GtkFileSystemHandle *handle =l->data;
 	  gtk_file_system_cancel_operation (handle);
+	  g_object_unref (handle);
         }
       g_slist_free (impl->pending_handles);
       impl->pending_handles = NULL;
@@ -5068,6 +5073,7 @@ gtk_file_chooser_default_dispose (GObjec
         {
 	  GtkFileSystemHandle *handle =l->data;
 	  gtk_file_system_cancel_operation (handle);
+	  g_object_unref (handle);
         }
       g_slist_free (impl->reload_icon_handles);
       impl->reload_icon_handles = NULL;
@@ -5079,6 +5085,7 @@ gtk_file_chooser_default_dispose (GObjec
         {
 	  GtkFileSystemHandle *handle =l->data;
 	  gtk_file_system_cancel_operation (handle);
+	  g_object_unref (handle);
         }
       g_slist_free (impl->loading_shortcuts);
       impl->loading_shortcuts = NULL;
@@ -5087,36 +5094,42 @@ gtk_file_chooser_default_dispose (GObjec
   if (impl->file_list_drag_data_received_handle)
     {
       gtk_file_system_cancel_operation (impl->file_list_drag_data_received_handle);
+      g_object_unref (impl->file_list_drag_data_received_handle);
       impl->file_list_drag_data_received_handle = NULL;
     }
 
   if (impl->update_current_folder_handle)
     {
       gtk_file_system_cancel_operation (impl->update_current_folder_handle);
+      g_object_unref (impl->update_current_folder_handle);
       impl->update_current_folder_handle = NULL;
     }
 
   if (impl->show_and_select_paths_handle)
     {
       gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
+      g_object_unref (impl->show_and_select_paths_handle);
       impl->show_and_select_paths_handle = NULL;
     }
 
   if (impl->should_respond_get_info_handle)
     {
       gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+      g_object_unref (impl->should_respond_get_info_handle);
       impl->should_respond_get_info_handle = NULL;
     }
 
   if (impl->update_from_entry_handle)
     {
       gtk_file_system_cancel_operation (impl->update_from_entry_handle);
+      g_object_unref (impl->update_from_entry_handle);
       impl->update_from_entry_handle = NULL;
     }
 
   if (impl->shortcuts_activate_iter_handle)
     {
       gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
+      g_object_unref (impl->shortcuts_activate_iter_handle);
       impl->shortcuts_activate_iter_handle = NULL;
     }
 
@@ -5791,6 +5804,7 @@ show_and_select_paths_finished_loading (
   browse_files_center_selected_row (data->impl);
 
   gtk_file_paths_free (data->paths);
+  g_object_unref_and_context (data->impl);
   g_free (data);
 }
 
@@ -5807,12 +5821,11 @@ show_and_select_paths_get_folder_cb (Gtk
     goto out;
 
   data->impl->show_and_select_paths_handle = NULL;
+  g_object_unref (handle);
 
   if (cancelled || error)
     goto out;
 
-  g_object_unref (handle);
-
   if (gtk_file_folder_is_finished_loading (folder))
     show_and_select_paths_finished_loading (folder, user_data);
   else
@@ -5823,11 +5836,9 @@ show_and_select_paths_get_folder_cb (Gtk
   return;
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   gtk_file_paths_free (data->paths);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static gboolean
@@ -5847,11 +5858,14 @@ show_and_select_paths (GtkFileChooserDef
     }
 
   info = g_new (struct ShowAndSelectPathsData, 1);
-  info->impl = g_object_ref (impl);
+  info->impl = g_object_ref_with_context (impl, &info->impl);
   info->paths = gtk_file_paths_copy (paths);
 
   if (impl->show_and_select_paths_handle)
-    gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
+    {
+      gtk_file_system_cancel_operation (impl->show_and_select_paths_handle);
+      g_object_unref (impl->show_and_select_paths_handle);
+    }
 
   impl->show_and_select_paths_handle =
     gtk_file_system_get_folder (impl->file_system, parent_path,
@@ -6156,6 +6170,7 @@ update_current_folder_get_info_cb (GtkFi
     goto out;
 
   impl->update_current_folder_handle = NULL;
+  g_object_unref (handle);
   impl->reload_state = RELOAD_EMPTY;
 
   set_busy_cursor (impl, FALSE);
@@ -6222,8 +6237,6 @@ update_current_folder_get_info_cb (GtkFi
 out:
   gtk_file_path_free (data->path);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static gboolean
@@ -6252,7 +6265,10 @@ gtk_file_chooser_default_update_current_
     }
 
   if (impl->update_current_folder_handle)
+  {
     gtk_file_system_cancel_operation (impl->update_current_folder_handle);
+    g_object_unref (impl->update_current_folder_handle);
+  }
 
   /* Test validity of path here.  */
   data = g_new0 (struct UpdateCurrentFolderData, 1);
@@ -6789,7 +6805,7 @@ add_shortcut_get_info_cb (GtkFileSystemH
   shortcuts_insert_path (data->impl, pos, FALSE, NULL, data->path, NULL, FALSE, SHORTCUTS_SHORTCUTS);
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   gtk_file_path_free (data->path);
   g_free (data);
 
@@ -6848,7 +6864,7 @@ gtk_file_chooser_default_add_shortcut_fo
     }
 
   data = g_new0 (struct AddShortcutData, 1);
-  data->impl = g_object_ref (impl);
+  data->impl = g_object_ref_with_context (impl, &data->impl);
   data->path = gtk_file_path_copy (path);
 
   handle = gtk_file_system_get_info (impl->file_system, path,
@@ -6886,6 +6902,7 @@ gtk_file_chooser_default_remove_shortcut
         {
 	  impl->loading_shortcuts = g_slist_remove (impl->loading_shortcuts, h);
 	  gtk_file_system_cancel_operation (h);
+	  g_object_unref (h);
           return TRUE;
 	}
     }
@@ -7225,6 +7242,7 @@ confirmation_confirm_get_info_cb (GtkFil
     goto out;
 
   data->impl->should_respond_get_info_handle = NULL;
+  g_object_unref (handle);
 
   if (cancelled)
     goto out;
@@ -7240,11 +7258,9 @@ confirmation_confirm_get_info_cb (GtkFil
     g_signal_emit_by_name (data->impl, "response-requested");
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   g_free (data->file_part);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 /* Does overwrite confirmation if appropriate, and returns whether the dialog
@@ -7273,11 +7289,14 @@ should_respond_after_confirm_overwrite (
 	g_assert (file_part != NULL);
 
 	data = g_new0 (struct GetDisplayNameData, 1);
-	data->impl = g_object_ref (impl);
+	data->impl = g_object_ref_with_context (impl, &data->impl);
 	data->file_part = g_strdup (file_part);
 
 	if (impl->should_respond_get_info_handle)
-	  gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+	  {
+	    gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+	    g_object_unref (impl->should_respond_get_info_handle);
+	  }
 
 	impl->should_respond_get_info_handle =
 	  gtk_file_system_get_info (impl->file_system, parent_path,
@@ -7325,7 +7344,7 @@ action_create_folder_cb (GtkFileSystemHa
     g_signal_emit_by_name (impl, "response-requested");
 
 out:
-  g_object_unref (impl);
+  g_object_unref_with_context (impl, action_create_folder_cb);
   g_object_unref (handle);
 }
 
@@ -7351,6 +7370,7 @@ save_entry_get_info_cb (GtkFileSystemHan
     goto out;
 
   data->impl->should_respond_get_info_handle = NULL;
+  g_object_unref (handle);
 
   set_busy_cursor (data->impl, FALSE);
 
@@ -7384,7 +7404,7 @@ save_entry_get_info_cb (GtkFileSystemHan
         {
 	  GtkFileSystemHandle *handle;
 
-	  g_object_ref (data->impl);
+	  g_object_ref_with_context (data->impl, action_create_folder_cb);
 	  handle = gtk_file_system_create_folder (data->impl->file_system,
 						  data->path,
 						  action_create_folder_cb,
@@ -7400,12 +7420,10 @@ save_entry_get_info_cb (GtkFileSystemHan
     }
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   gtk_file_path_free (data->path);
   gtk_file_path_free (data->parent_path);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -7618,13 +7636,16 @@ gtk_file_chooser_default_should_respond 
 	      parent_path = gtk_file_path_copy (_gtk_file_chooser_entry_get_current_folder (entry));
 
 	      data = g_new0 (struct SaveEntryData, 1);
-	      data->impl = g_object_ref (impl);
+	      data->impl = g_object_ref_with_context (impl, &data->impl);
 	      data->file_exists_and_is_not_folder = file_exists_and_is_not_folder;
 	      data->parent_path = parent_path; /* Takes ownership */
 	      data->path = gtk_file_path_copy (path);
 
 	      if (impl->should_respond_get_info_handle)
-		gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+		{
+		  gtk_file_system_cancel_operation (impl->should_respond_get_info_handle);
+		  g_object_unref (impl->should_respond_get_info_handle);
+		}
 
 	      impl->should_respond_get_info_handle =
 	        gtk_file_system_get_info (impl->file_system, parent_path,
@@ -7832,6 +7853,7 @@ shortcuts_activate_volume_mount_cb (GtkF
     goto out;
 
   impl->shortcuts_activate_iter_handle = NULL;
+  g_object_unref (handle);
 
   set_busy_cursor (impl, FALSE);
 
@@ -7858,8 +7880,7 @@ shortcuts_activate_volume_mount_cb (GtkF
     }
 
 out:
-  g_object_unref (impl);
-  g_object_unref (handle);
+  g_object_unref_with_context (impl, shortcuts_activate_volume_mount_cb);
 }
 
 
@@ -7875,16 +7896,17 @@ shortcuts_activate_volume (GtkFileChoose
   /* We ref the file chooser since volume_mount() may run a main loop, and the
    * user could close the file chooser window in the meantime.
    */
-  g_object_ref (impl);
+  g_object_ref_and_context (impl);
 
   if (!gtk_file_system_volume_get_is_mounted (impl->file_system, volume))
     {
       set_busy_cursor (impl, TRUE);
 
+      g_assert (impl->shortcuts_activate_iter_handle == NULL);
       impl->shortcuts_activate_iter_handle =
         gtk_file_system_volume_mount (impl->file_system, volume,
 				      shortcuts_activate_volume_mount_cb,
-				      g_object_ref (impl));
+				      g_object_ref_with_context (impl, shortcuts_activate_volume_mount_cb));
     }
   else
     {
@@ -7896,7 +7918,7 @@ shortcuts_activate_volume (GtkFileChoose
         }
     }
 
-  g_object_unref (impl);
+  g_object_unref_and_context (impl);
 }
 
 /* Opens the folder or volume at the specified iter in the shortcuts model */
@@ -7919,6 +7941,7 @@ shortcuts_activate_get_info_cb (GtkFileS
     goto out;
 
   data->impl->shortcuts_activate_iter_handle = NULL;
+  g_object_unref (handle);
 
   if (cancelled)
     goto out;
@@ -7929,11 +7952,9 @@ shortcuts_activate_get_info_cb (GtkFileS
     gtk_file_chooser_default_select_path (GTK_FILE_CHOOSER (data->impl), data->path, NULL);
 
 out:
-  g_object_unref (data->impl);
+  g_object_unref_and_context (data->impl);
   gtk_file_path_free (data->path);
   g_free (data);
-
-  g_object_unref (handle);
 }
 
 static void
@@ -7957,6 +7978,7 @@ shortcuts_activate_iter (GtkFileChooserD
   if (impl->shortcuts_activate_iter_handle)
     {
       gtk_file_system_cancel_operation (impl->shortcuts_activate_iter_handle);
+      g_object_unref (impl->shortcuts_activate_iter_handle);
       impl->shortcuts_activate_iter_handle = NULL;
     }
 
@@ -7973,7 +7995,7 @@ shortcuts_activate_iter (GtkFileChooserD
       struct ShortcutsActivateData *data;
 
       data = g_new0 (struct ShortcutsActivateData, 1);
-      data->impl = g_object_ref (impl);
+      data->impl = g_object_ref_with_context (impl, &data->impl);
       data->path = gtk_file_path_copy (col_data);
 
       impl->shortcuts_activate_iter_handle =
Index: gtk/gtkfilechooserentry.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilechooserentry.c,v
retrieving revision 1.37
diff -u -p -r1.37 gtkfilechooserentry.c
--- gtk/gtkfilechooserentry.c	6 Jul 2006 05:14:01 -0000	1.37
+++ gtk/gtkfilechooserentry.c	19 Jul 2006 22:41:51 -0000
@@ -616,7 +616,7 @@ load_directory_get_folder_callback (GtkF
 				  GTK_TREE_MODEL (chooser_entry->completion_store));
 
 out:
-  g_object_unref (chooser_entry);
+  g_object_unref_with_context (chooser_entry, load_directory_get_folder_callback);
   g_object_unref (handle);
 }
 
@@ -650,7 +650,7 @@ load_directory_callback (GtkFileChooserE
 			        chooser_entry->current_folder_path,
 			        GTK_FILE_INFO_DISPLAY_NAME | GTK_FILE_INFO_IS_FOLDER,
 			        load_directory_get_folder_callback,
-			        g_object_ref (chooser_entry));
+			        g_object_ref_with_context (chooser_entry, load_directory_get_folder_callback));
 
  done:
   
@@ -890,9 +890,9 @@ _gtk_file_chooser_entry_set_file_system 
   if (file_system != chooser_entry->file_system)
     {
       if (chooser_entry->file_system)
-	g_object_unref (chooser_entry->file_system);
+	g_object_unref_and_context (chooser_entry->file_system);
 
-      chooser_entry->file_system = g_object_ref (file_system);
+      chooser_entry->file_system = g_object_ref_with_context (file_system, &chooser_entry->file_system);
     }
 }
 
Index: gtk/gtkfilesystem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystem.c,v
retrieving revision 1.58
diff -u -p -r1.58 gtkfilesystem.c
--- gtk/gtkfilesystem.c	22 May 2006 12:53:13 -0000	1.58
+++ gtk/gtkfilesystem.c	19 Jul 2006 22:41:52 -0000
@@ -71,7 +71,7 @@ gtk_file_info_new  (void)
 {
   GtkFileInfo *info;
   
-  info = g_new0 (GtkFileInfo, 1);
+  info = g_slice_new0 (GtkFileInfo);
 
   return info;
 }
@@ -83,7 +83,9 @@ gtk_file_info_copy (GtkFileInfo *info)
 
   g_return_val_if_fail (info != NULL, NULL);
 
-  new_info = g_memdup (info, sizeof (GtkFileInfo));
+  new_info = g_slice_new (GtkFileInfo);
+  *new_info = *info;
+
   if (new_info->display_name)
     new_info->display_name = g_strdup (new_info->display_name);
   if (new_info->display_key)
@@ -103,16 +105,12 @@ gtk_file_info_free (GtkFileInfo *info)
 {
   g_return_if_fail (info != NULL);
 
-  if (info->display_name)
-    g_free (info->display_name);
-  if (info->mime_type)
-    g_free (info->mime_type);
-  if (info->display_key)
-    g_free (info->display_key);
-  if (info->icon_name)
-    g_free (info->icon_name);
+  g_free (info->display_name);
+  g_free (info->mime_type);
+  g_free (info->display_key);
+  g_free (info->icon_name);
 
-  g_free (info);
+  g_slice_free (GtkFileInfo, info);
 }
 
 G_CONST_RETURN gchar *
@@ -158,8 +156,7 @@ gtk_file_info_set_display_name (GtkFileI
   if (display_name == info->display_name)
     return;
 
-  if (info->display_name)
-    g_free (info->display_name);
+  g_free (info->display_name);
   if (info->display_key)
     {
       g_free (info->display_key);
@@ -217,8 +214,7 @@ gtk_file_info_set_mime_type (GtkFileInfo
 {
   g_return_if_fail (info != NULL);
   
-  if (info->mime_type)
-    g_free (info->mime_type);
+  g_free (info->mime_type);
 
   info->mime_type = g_strdup (mime_type);
 }
@@ -264,8 +260,7 @@ gtk_file_info_set_icon_name (GtkFileInfo
 {
   g_return_if_fail (info != NULL);
   
-  if (info->icon_name)
-    g_free (info->icon_name);
+  g_free (info->icon_name);
 
   info->icon_name = g_strdup (icon_name);
 }
@@ -341,6 +336,16 @@ gtk_file_system_handle_init (GtkFileSyst
 }
 
 static void
+gtk_file_system_handle_finalize (GObject      *object)
+{
+  GtkFileSystemHandle *handle = GTK_FILE_SYSTEM_HANDLE (object);
+
+  g_object_unref_and_context (handle->file_system);
+
+  G_OBJECT_CLASS (gtk_file_system_handle_parent_class)->finalize (object);
+}
+
+static void
 gtk_file_system_handle_set_property (GObject      *object,
 				     guint         prop_id,
 				     const GValue *value,
@@ -377,6 +382,7 @@ gtk_file_system_handle_class_init (GtkFi
   o_class = (GObjectClass *)klass;
   o_class->set_property = gtk_file_system_handle_set_property;
   o_class->get_property = gtk_file_system_handle_get_property;
+  o_class->finalize     = gtk_file_system_handle_finalize;
 
   g_object_class_install_property (o_class,
 				   PROP_CANCELLED,
Index: gtk/gtkfilesystemmodel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystemmodel.c,v
retrieving revision 1.45
diff -u -p -r1.45 gtkfilesystemmodel.c
--- gtk/gtkfilesystemmodel.c	14 May 2006 04:25:29 -0000	1.45
+++ gtk/gtkfilesystemmodel.c	19 Jul 2006 22:41:54 -0000
@@ -210,7 +210,7 @@ gtk_file_system_model_finalize (GObject 
     gtk_file_path_free (model->root_path);
 
   if (model->file_system)
-    g_object_unref (model->file_system);
+    g_object_unref_and_context (model->file_system);
 
   children = model->roots;
   while (children)
@@ -667,7 +667,7 @@ got_root_folder_cb (GtkFileSystemHandle 
   model->roots = (FileModelNode *) g_slist_reverse ((GSList *)model->roots);
 
 out:
-  g_object_unref (model);
+  g_object_unref_with_context (model, got_root_folder_cb);
   g_object_unref (handle);
 }
 
@@ -716,7 +716,7 @@ _gtk_file_system_model_new (GtkFileSyste
   /* Then, actually create the model and the root nodes */
 
   model = g_object_new (GTK_TYPE_FILE_SYSTEM_MODEL, NULL);
-  model->file_system = g_object_ref (file_system);
+  model->file_system = g_object_ref_with_context (file_system, &model->file_system);
   if (max_depth < 0)
     model->max_depth = G_MAXUSHORT;
   else
@@ -730,7 +730,7 @@ _gtk_file_system_model_new (GtkFileSyste
 
   handle = gtk_file_system_get_folder (file_system, root_path, types,
 				       got_root_folder_cb,
-				       g_object_ref (model));
+				       g_object_ref_with_context (model, got_root_folder_cb));
   if (!handle)
     {
       /* In this case got_root_folder_cb() will never be called, so we
@@ -1118,7 +1118,7 @@ out:
   gtk_file_paths_free (info->paths);
   g_slist_foreach (info->cleanups, (GFunc)g_object_unref, NULL);
   g_slist_free (info->cleanups);
-  g_object_unref (info->model);
+  g_object_unref_and_context (info->model);
   g_free (info);
 
   g_object_unref (handle);
@@ -1213,7 +1213,7 @@ _gtk_file_system_model_path_do (GtkFileS
     {
       info = g_new0 (struct RefPathData, 1);
       info->paths = paths;
-      info->model = g_object_ref (model);
+      info->model = g_object_ref_with_context (model, &info->model);
       info->func = func;
       info->user_data = user_data;
       info->node = node;
@@ -1608,7 +1608,7 @@ get_children_get_folder_cb (GtkFileSyste
   g_object_set_data (G_OBJECT (data->node->folder), I_("model-node"), data->node);
 
 out:
-  g_object_unref (data->model);
+  g_object_unref_and_context (data->model);
   g_free (data);
 
   g_object_unref (handle);
@@ -1635,7 +1635,7 @@ file_model_node_get_children (GtkFileSys
 	  GtkFileSystemHandle *handle;
 
 	  data = g_new (struct GetChildrenData, 1);
-	  data->model = g_object_ref (model);
+	  data->model = g_object_ref_with_context (model, &data->model);
 	  data->node = node;
 
 	  handle =
Index: gtk/gtkfilesystemunix.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystemunix.c,v
retrieving revision 1.77
diff -u -p -r1.77 gtkfilesystemunix.c
--- gtk/gtkfilesystemunix.c	6 Jul 2006 05:14:01 -0000	1.77
+++ gtk/gtkfilesystemunix.c	19 Jul 2006 22:41:56 -0000
@@ -420,9 +420,9 @@ dispatch_get_info_callback (struct get_i
   if (info->error)
     g_error_free (info->error);
 
-  g_object_unref (info->handle);
+  g_object_unref_and_context (info->handle);
 
-  g_free (info);
+  g_slice_free (struct get_info_callback, info);
 }
 
 static inline void
@@ -434,9 +434,9 @@ queue_get_info_callback (GtkFileSystemGe
 {
   struct get_info_callback *info;
 
-  info = g_new (struct get_info_callback, 1);
+  info = g_slice_new (struct get_info_callback);
   info->callback = callback;
-  info->handle = handle;
+  info->handle = g_object_ref_with_context (handle, &info->handle);
   info->file_info = file_info;
   info->error = error;
   info->data = data;
@@ -462,9 +462,9 @@ dispatch_get_folder_callback (struct get
   if (info->error)
     g_error_free (info->error);
 
-  g_object_unref (info->handle);
+  g_object_unref_and_context (info->handle);
 
-  g_free (info);
+  g_slice_free (struct get_folder_callback, info);
 }
 
 static inline void
@@ -476,9 +476,9 @@ queue_get_folder_callback (GtkFileSystem
 {
   struct get_folder_callback *info;
 
-  info = g_new (struct get_folder_callback, 1);
+  info = g_slice_new (struct get_folder_callback);
   info->callback = callback;
-  info->handle = handle;
+  info->handle = g_object_ref_with_context (handle, &info->handle);
   info->folder = folder;
   info->error = error;
   info->data = data;
@@ -507,9 +507,9 @@ dispatch_create_folder_callback (struct 
   if (info->path)
     gtk_file_path_free (info->path);
 
-  g_object_unref (info->handle);
+  g_object_unref_and_context (info->handle);
 
-  g_free (info);
+  g_slice_free (struct create_folder_callback, info);
 }
 
 static inline void
@@ -521,9 +521,9 @@ queue_create_folder_callback (GtkFileSys
 {
   struct create_folder_callback *info;
 
-  info = g_new (struct create_folder_callback, 1);
+  info = g_slice_new (struct create_folder_callback);
   info->callback = callback;
-  info->handle = handle;
+  info->handle = g_object_ref_with_context (handle, &info->handle);
   info->path = gtk_file_path_copy (path);
   info->error = error;
   info->data = data;
@@ -549,9 +549,9 @@ dispatch_volume_mount_callback (struct v
   if (info->error)
     g_error_free (info->error);
 
-  g_object_unref (info->handle);
+  g_object_unref_and_context (info->handle);
 
-  g_free (info);
+  g_slice_free (struct volume_mount_callback, info);
 }
 
 static inline void
@@ -563,9 +563,9 @@ queue_volume_mount_callback (GtkFileSyst
 {
   struct volume_mount_callback *info;
 
-  info = g_new (struct volume_mount_callback, 1);
+  info = g_slice_new (struct volume_mount_callback);
   info->callback = callback;
-  info->handle = handle;
+  info->handle = g_object_ref_with_context(handle, &info->handle);
   info->volume = volume;
   info->error = error;
   info->data = data;
@@ -621,7 +621,7 @@ execute_callbacks_idle (gpointer data)
 	    break;
         }
 
-      g_free (info);
+      g_slice_free (struct callback_info, info);
     }
 
   g_slist_free (callbacks);
@@ -639,7 +639,7 @@ queue_callback (enum callback_types type
 {
   struct callback_info *info;
 
-  info = g_new (struct callback_info, 1);
+  info = g_slice_new (struct callback_info);
   info->type = type;
 
   switch (type)
@@ -664,7 +664,8 @@ queue_callback (enum callback_types type
   callbacks = g_slist_append (callbacks, info);
 
   if (!execute_callbacks_idle_id)
-    execute_callbacks_idle_id = g_idle_add (execute_callbacks_idle, NULL);
+    execute_callbacks_idle_id = g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+	execute_callbacks_idle, NULL, (GDestroyNotify)execute_callbacks_idle);
 }
 
 static GtkFileSystemHandle *
@@ -673,7 +674,7 @@ create_handle (GtkFileSystem *file_syste
   GtkFileSystemHandle *handle;
 
   handle = g_object_new (GTK_TYPE_FILE_SYSTEM_HANDLE, NULL);
-  handle->file_system = file_system;
+  handle->file_system = g_object_ref_with_context (file_system, &handle->file_system);
 
   return handle;
 }
@@ -705,7 +706,6 @@ gtk_file_system_unix_get_info (GtkFileSy
 
   if (!stat_with_error (filename, &statbuf, &error))
     {
-      g_object_ref (handle);
       queue_get_info_callback (callback, handle, NULL, error, data);
       return handle;
     }
@@ -720,7 +720,6 @@ gtk_file_system_unix_get_info (GtkFileSy
   info = create_file_info (NULL, filename, basename, types, &statbuf,
                            mime_type);
   g_free (basename);
-  g_object_ref (handle);
   queue_get_info_callback (callback, handle, info, NULL, data);
 
   return handle;
@@ -843,7 +842,6 @@ gtk_file_system_unix_get_folder (GtkFile
 		       display_name,
 		       g_strerror (my_errno));
 
-	  g_object_ref (handle);
 	  queue_get_folder_callback (callback, handle, NULL, error, data);
 
 	  g_free (display_name);
@@ -881,7 +879,6 @@ gtk_file_system_unix_get_folder (GtkFile
   if (set_asof)
     folder_unix->asof = time (NULL);
 
-  g_object_ref (handle);
   queue_get_folder_callback (callback, handle, GTK_FILE_FOLDER (folder_unix), NULL, data);
 
   /* Start loading the folder contents in an idle */
@@ -929,14 +926,12 @@ gtk_file_system_unix_create_folder (GtkF
 		   display_name,
 		   g_strerror (save_errno));
       
-      g_object_ref (handle);
       queue_create_folder_callback (callback, handle, path, error, data);
 
       g_free (display_name);
       return handle;
     }
 
-  g_object_ref (handle);
   queue_create_folder_callback (callback, handle, path, NULL, data);
 
   parent = get_parent_dir (filename);
@@ -952,7 +947,7 @@ gtk_file_system_unix_create_folder (GtkF
 	  struct stat_info_entry *entry;
 
 	  /* Make sure the new folder exists in the parent's folder */
-	  entry = g_new0 (struct stat_info_entry, 1);
+	  entry = g_slice_new0 (struct stat_info_entry);
 	  if (folder_unix->is_network_dir)
 	    {
 	      entry->statbuf.st_mode = S_IFDIR;
@@ -1033,7 +1028,6 @@ gtk_file_system_unix_volume_mount (GtkFi
 	       GTK_FILE_SYSTEM_ERROR_FAILED,
 	       _("This file system does not support mounting"));
 
-  g_object_ref (handle);
   queue_volume_mount_callback (callback, handle, volume, error, data);
 
   return handle;
@@ -2218,7 +2212,7 @@ create_stat_info_entry_and_emit_add (Gtk
   GtkFilePath *path;
   struct stat_info_entry *entry;
 
-  entry = g_new0 (struct stat_info_entry, 1);
+  entry = g_slice_new0 (struct stat_info_entry);
 
   if ((folder_unix->types & STAT_NEEDED_MASK) != 0)
     entry->statbuf = *statbuf;
@@ -2357,7 +2351,7 @@ static void
 free_stat_info_entry (struct stat_info_entry *entry)
 {
   g_free (entry->mime_type);
-  g_free (entry);
+  g_slice_free (struct stat_info_entry, entry);
 }
 
 static gboolean
@@ -2385,7 +2379,7 @@ fill_in_names (GtkFileFolderUnix *folder
       if (!basename)
 	break;
 
-      entry = g_new0 (struct stat_info_entry, 1);
+      entry = g_slice_new0 (struct stat_info_entry);
       if (folder_unix->is_network_dir)
 	{
 	  entry->statbuf.st_mode = S_IFDIR;
Index: gtk/gtkfilesystemwin32.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystemwin32.c,v
retrieving revision 1.37
diff -u -p -r1.37 gtkfilesystemwin32.c
--- gtk/gtkfilesystemwin32.c	21 May 2006 23:48:49 -0000	1.37
+++ gtk/gtkfilesystemwin32.c	19 Jul 2006 22:41:58 -0000
@@ -760,7 +760,7 @@ create_handle (GtkFileSystem *file_syste
   GtkFileSystemHandle *handle;
 
   handle = g_object_new (GTK_TYPE_FILE_SYSTEM_HANDLE, NULL);
-  handle->file_system = file_system;
+  handle->file_system = g_object_ref_with_context (file_system, &handle->file_system);
 
   return handle;
 }
Index: gtk/gtkgc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkgc.c,v
retrieving revision 1.17
diff -u -p -r1.17 gtkgc.c
--- gtk/gtkgc.c	4 Jan 2006 07:06:12 -0000	1.17
+++ gtk/gtkgc.c	19 Jul 2006 22:41:58 -0000
@@ -92,7 +92,7 @@ void
 gtk_gc_release (GdkGC *gc)
 {
   if (initialize)
-    gtk_gc_init ();
+    return;
 
   g_cache_remove (gc_cache, gc);
 }
@@ -101,10 +101,17 @@ static void 
 free_gc_drawable (gpointer data)
 {
   GtkGCDrawable *drawable = data;
-  g_object_unref (drawable->drawable);
+  g_object_unref_with_context (drawable->drawable, drawable->drawable);
   g_slice_free (GtkGCDrawable, drawable);
 }
 
+static void
+on_drawable_screen_closed (GdkScreen *screen, GHashTable *ht)
+{
+  g_object_set_qdata (G_OBJECT (screen), quark_gtk_gc_drawable_ht, NULL);
+  g_hash_table_destroy (ht);
+}
+
 static GHashTable*
 gtk_gc_get_drawable_ht (GdkScreen *screen)
 {
@@ -114,9 +121,10 @@ gtk_gc_get_drawable_ht (GdkScreen *scree
       ht = g_hash_table_new_full ((GHashFunc) gtk_gc_drawable_hash,
 				  (GEqualFunc) gtk_gc_drawable_equal,
 				  NULL, free_gc_drawable);
-      g_object_set_qdata_full (G_OBJECT (screen), 
-			       quark_gtk_gc_drawable_ht, ht, 
-			       (GDestroyNotify)g_hash_table_destroy);
+      g_signal_connect (screen, "closed",
+	  G_CALLBACK (on_drawable_screen_closed), ht);
+      g_object_set_qdata (G_OBJECT (screen),
+	  quark_gtk_gc_drawable_ht, ht);
     }
   
   return ht;
@@ -188,7 +196,7 @@ gtk_gc_new (gpointer key)
 static void
 gtk_gc_destroy (gpointer value)
 {
-  g_object_unref (value);
+  g_object_unref_with_context (value, value);
 }
 
 static guint
Index: gtk/gtkhsv.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkhsv.c,v
retrieving revision 1.44
diff -u -p -r1.44 gtkhsv.c
--- gtk/gtkhsv.c	14 May 2006 04:25:29 -0000	1.44
+++ gtk/gtkhsv.c	19 Jul 2006 22:42:00 -0000
@@ -300,7 +300,7 @@ gtk_hsv_realize (GtkWidget *widget)
   parent_window = gtk_widget_get_parent_window (widget);
   
   widget->window = parent_window;
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   priv->window = gdk_window_new (parent_window, &attr, attr_mask);
   gdk_window_set_user_data (priv->window, hsv);
Index: gtk/gtkiconfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkiconfactory.c,v
retrieving revision 1.88
diff -u -p -r1.88 gtkiconfactory.c
--- gtk/gtkiconfactory.c	19 May 2006 19:04:26 -0000	1.88
+++ gtk/gtkiconfactory.c	19 Jul 2006 22:42:02 -0000
@@ -248,11 +248,16 @@ static GSList *default_factories = NULL;
 void
 gtk_icon_factory_add_default (GtkIconFactory *factory)
 {
-  g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
+  if (factory)
+    {
+      g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
 
-  g_object_ref (factory);
-  
-  default_factories = g_slist_prepend (default_factories, factory);
+      g_object_ref (factory);
+
+      default_factories = g_slist_prepend (default_factories, factory);
+    }
+  else
+    _gtk_icon_factory_ensure_default_icons ();
 }
 
 /**
@@ -267,6 +272,14 @@ gtk_icon_factory_add_default (GtkIconFac
 void
 gtk_icon_factory_remove_default (GtkIconFactory  *factory)
 {
+  if (!factory)
+    {
+      factory = gtk_default_icons;
+      gtk_default_icons = NULL;
+      if (!factory)
+	return;
+    }
+
   g_return_if_fail (GTK_IS_ICON_FACTORY (factory));
 
   default_factories = g_slist_remove (default_factories, factory);
@@ -1036,7 +1049,7 @@ gtk_icon_size_register_alias (const gcha
 
   if (!ia)
     {
-      ia = g_new (IconAlias, 1);
+      ia = g_slice_new (IconAlias);
       ia->name = g_strdup (alias);
       ia->target = target;
 
@@ -1553,6 +1566,23 @@ find_and_render_icon_source (GtkIconSet 
 
 extern GtkIconCache *_builtin_cache;
 
+#include <gdk-pixbuf/gdk-pixdata.h>
+#include "_gtk_icon_cache_missing_pb.c"
+static GdkPixbuf*
+_gtk_icon_cache_missing_image (void)
+{
+  GdkPixbuf *pixbuf;
+
+  pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
+      GTK_STOCK_MISSING_IMAGE,
+      "24");
+
+  if (!pixbuf) /* serious, unable to load stock icons! */
+      pixbuf = gdk_pixbuf_from_pixdata (&_gtk_icon_cache_missing_pb, TRUE, NULL);
+
+  return pixbuf;
+}
+
 static GdkPixbuf*
 render_fallback_image (GtkStyle          *style,
                        GtkTextDirection   direction,
@@ -1566,11 +1596,10 @@ render_fallback_image (GtkStyle         
 
   if (fallback_source.type == GTK_ICON_SOURCE_EMPTY)
     {
-      GdkPixbuf *pixbuf = _gtk_icon_cache_get_icon (_builtin_cache,
-						    GTK_STOCK_MISSING_IMAGE,
-						    "24");
+      GdkPixbuf *pixbuf = _gtk_icon_cache_missing_image ();
+
       gtk_icon_source_set_pixbuf (&fallback_source, pixbuf);
-      g_object_unref (pixbuf);
+      g_object_unref_with_context (pixbuf, pixbuf);
     }
   
   return gtk_style_render_icon (style,
@@ -1615,14 +1644,11 @@ gtk_icon_set_render_icon (GtkIconSet    
                           GtkWidget         *widget,
                           const char        *detail)
 {
-  GdkPixbuf *icon;
+  GdkPixbuf *icon = NULL;
   
   g_return_val_if_fail (icon_set != NULL, NULL);
   g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
 
-  if (icon_set->sources == NULL)
-    return render_fallback_image (style, direction, state, size, widget, detail);
-
   if (detail == NULL)
     {
       icon = find_in_cache (icon_set, style, direction,
@@ -1630,14 +1656,15 @@ gtk_icon_set_render_icon (GtkIconSet    
       
       if (icon)
 	{
-	  g_object_ref (icon);
+	  g_object_ref_with_context (icon, icon);
 	  return icon;
 	}
     }
 
 
-  icon = find_and_render_icon_source (icon_set, style, direction, state, size,
-				      widget, detail);
+  if (icon_set->sources != NULL)
+    icon = find_and_render_icon_source (icon_set, style, direction, state, size,
+	widget, detail);
 
   if (icon == NULL)
     icon = render_fallback_image (style, direction, state, size, widget, detail);
@@ -1723,6 +1750,7 @@ gtk_icon_set_add_source (GtkIconSet *ico
   icon_set->sources = g_slist_insert_sorted (icon_set->sources,
                                              gtk_icon_source_copy (source),
                                              icon_source_compare);
+  clear_cache (icon_set, FALSE);
 }
 
 /**
@@ -1890,10 +1918,10 @@ gtk_icon_source_copy (const GtkIconSourc
       copy->cp_filename = g_strdup (copy->cp_filename);
 #endif
       if (copy->filename_pixbuf)
-	g_object_ref (copy->filename_pixbuf);
+	g_object_ref_and_context (copy->filename_pixbuf);
       break;
     case GTK_ICON_SOURCE_PIXBUF:
-      g_object_ref (copy->source.pixbuf);
+      g_object_ref_and_context (copy->source.pixbuf);
       break;
     default:
       g_assert_not_reached();
@@ -1952,11 +1980,11 @@ icon_source_clear (GtkIconSource *source
       source->cp_filename = NULL;
 #endif
       if (source->filename_pixbuf) 
-	g_object_unref (source->filename_pixbuf);
+	g_object_unref_and_context (source->filename_pixbuf);
       source->filename_pixbuf = NULL;
       break;
     case GTK_ICON_SOURCE_PIXBUF:
-      g_object_unref (source->source.pixbuf);
+      g_object_unref_and_context (source->source.pixbuf);
       source->source.pixbuf = NULL;
       break;
     default:
@@ -2048,7 +2076,7 @@ gtk_icon_source_set_pixbuf (GtkIconSourc
   if (pixbuf != NULL)
     {
       source->type = GTK_ICON_SOURCE_PIXBUF;
-      source->source.pixbuf = g_object_ref (pixbuf);
+      source->source.pixbuf = g_object_ref_with_context (pixbuf, &source->source.pixbuf);
     }
 }
 
@@ -2389,6 +2417,7 @@ struct _CachedIcon
   GtkIconSize size;
 
   GdkPixbuf *pixbuf;
+  gboolean have_ref;
 };
 
 static void
@@ -2402,14 +2431,83 @@ ensure_cache_up_to_date (GtkIconSet *ico
 }
 
 static void
-cached_icon_free (CachedIcon *icon)
+cached_icon_unlink (GtkIconSet *icon_set, GdkPixbuf *dead)
 {
-  g_object_unref (icon->pixbuf);
+  GSList *tmp_list;
+  GSList **prev;
+
+  prev = &icon_set->cache;
+  tmp_list = icon_set->cache;
+  while (tmp_list != NULL)
+    {
+      CachedIcon *icon = tmp_list->data;
+
+      if (icon->pixbuf == dead)
+	{
+	  if (icon->style)
+	    g_object_unref_and_context (icon->style);
+
+	  g_slice_free (CachedIcon, icon);
+
+	  *prev = tmp_list->next;
+	  g_slist_free1 (tmp_list);
+	  break;
+	}
+
+      prev = &tmp_list->next;
+      tmp_list = tmp_list->next;
+    }
+}
+
+static void
+cached_icon_free (GtkIconSet *icon_set, CachedIcon *icon)
+{
+  if (icon->have_ref)
+    g_object_unref_and_context (icon->pixbuf);
+  else
+    g_object_weak_unref (G_OBJECT (icon->pixbuf),
+       	(GWeakNotify) cached_icon_unlink, icon_set);
 
   if (icon->style)
-    g_object_unref (icon->style);
+    g_object_unref_and_context (icon->style);
 
-  g_free (icon);
+  g_slice_free (CachedIcon, icon);
+}
+
+static void
+trim_cache (GtkIconSet *icon_set)
+{
+  while (icon_set->cache_size >= NUM_CACHED_ICONS)
+    {
+      /* Remove oldest item in the cache */
+      GSList *tmp_list;
+      CachedIcon *icon;
+
+      tmp_list = icon_set->cache;
+
+      /* Find last active link */
+      g_assert (NUM_CACHED_ICONS > 2);
+      icon = tmp_list->data;
+      g_assert (icon->have_ref == TRUE);
+      icon = tmp_list->next->data;
+      while (icon->have_ref)
+	{
+	  tmp_list = tmp_list->next;
+	  g_assert (tmp_list->next != NULL);
+	  icon = tmp_list->next->data;
+	}
+
+      g_assert (tmp_list != NULL);
+      icon = tmp_list->data;
+      g_assert (icon->have_ref == TRUE);
+
+      g_object_weak_ref (G_OBJECT (icon->pixbuf),
+	  (GWeakNotify) cached_icon_unlink, icon_set);
+      icon->have_ref = FALSE;
+      g_object_unref_and_context (icon->pixbuf);
+
+      icon_set->cache_size--;
+    }
 }
 
 static GdkPixbuf *
@@ -2442,6 +2540,17 @@ find_in_cache (GtkIconSet      *icon_set
               tmp_list->next = icon_set->cache;
               icon_set->cache = tmp_list;
             }
+
+	  if (!icon->have_ref)
+	    {
+	      g_object_ref_and_context (icon->pixbuf);
+	      g_object_weak_unref (G_OBJECT (icon->pixbuf),
+		  (GWeakNotify) cached_icon_unlink, icon_set);
+	      icon->have_ref = TRUE;
+	      icon_set->cache_size++;
+
+	      trim_cache (icon_set);
+	    }
           
           return icon->pixbuf;
         }
@@ -2465,53 +2574,29 @@ add_to_cache (GtkIconSet      *icon_set,
 
   ensure_cache_up_to_date (icon_set);
 
-  g_object_ref (pixbuf);
+  icon = g_slice_new (CachedIcon);
+  icon_set->cache = g_slist_prepend (icon_set->cache, icon);
+  icon_set->cache_size++;
 
+  icon->style = style;
   /* We have to ref the style, since if the style was finalized
    * its address could be reused by another style, creating a
    * really weird bug
    */
-  
   if (style)
-    g_object_ref (style);
-
-  icon = g_new (CachedIcon, 1);
-  icon_set->cache = g_slist_prepend (icon_set->cache, icon);
-  icon_set->cache_size++;
+    g_object_ref_with_context (style, &icon->style);
 
-  icon->style = style;
   icon->direction = direction;
   icon->state = state;
   icon->size = size;
   icon->pixbuf = pixbuf;
+  g_object_ref_with_context (pixbuf, &icon->pixbuf);
+  icon->have_ref = TRUE;
 
   if (icon->style)
     attach_to_style (icon_set, icon->style);
-  
-  if (icon_set->cache_size >= NUM_CACHED_ICONS)
-    {
-      /* Remove oldest item in the cache */
-      GSList *tmp_list;
-      
-      tmp_list = icon_set->cache;
-
-      /* Find next-to-last link */
-      g_assert (NUM_CACHED_ICONS > 2);
-      while (tmp_list->next->next)
-        tmp_list = tmp_list->next;
-
-      g_assert (tmp_list != NULL);
-      g_assert (tmp_list->next != NULL);
-      g_assert (tmp_list->next->next == NULL);
 
-      /* Free the last icon */
-      icon = tmp_list->next->data;
-
-      g_slist_free (tmp_list->next);
-      tmp_list->next = NULL;
-
-      cached_icon_free (icon);
-    }
+  trim_cache (icon_set);
 }
 
 static void
@@ -2543,7 +2628,7 @@ clear_cache (GtkIconSet *icon_set,
             }
         }
       
-      cached_icon_free (icon);      
+      cached_icon_free (icon_set, icon);      
       
       tmp_list = g_slist_next (tmp_list);
     }
@@ -2564,17 +2649,21 @@ copy_cache (GtkIconSet *icon_set,
   while (tmp_list != NULL)
     {
       CachedIcon *icon = tmp_list->data;
-      CachedIcon *icon_copy = g_new (CachedIcon, 1);
+      CachedIcon *icon_copy = g_slice_new (CachedIcon);
 
       *icon_copy = *icon;
 
       if (icon_copy->style)
 	{
 	  attach_to_style (copy_recipient, icon_copy->style);
-	  g_object_ref (icon_copy->style);
+	  g_object_ref_and_context (icon_copy->style);
 	}
         
-      g_object_ref (icon_copy->pixbuf);
+      if (icon_copy->have_ref)
+	g_object_ref_and_context (icon_copy->pixbuf);
+      else
+	g_object_weak_ref (G_OBJECT (icon_copy->pixbuf),
+	    (GWeakNotify) cached_icon_unlink, icon_set);
 
       icon_copy->size = icon->size;
       
Index: gtk/gtkicontheme.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkicontheme.c,v
retrieving revision 1.80
diff -u -p -r1.80 gtkicontheme.c
--- gtk/gtkicontheme.c	7 Jul 2006 05:24:00 -0000	1.80
+++ gtk/gtkicontheme.c	19 Jul 2006 22:42:05 -0000
@@ -369,7 +369,7 @@ display_closed (GdkDisplay   *display,
 
   if (was_screen_singleton)
     {
-      g_object_unref (icon_theme);
+      g_object_unref_with_context (icon_theme, icon_theme);
     }
 }
 
@@ -395,7 +395,7 @@ update_current_theme (GtkIconTheme *icon
       if (!theme)
 	theme = g_strdup (DEFAULT_THEME_NAME);
 
-      if (strcmp (priv->current_theme, theme) != 0)
+      if (!priv->current_theme || strcmp (priv->current_theme, theme) != 0)
 	{
 	  g_free (priv->current_theme);
 	  priv->current_theme = theme;
@@ -2523,9 +2523,8 @@ load_svg_at_size (const gchar *filename,
   
  bail:
   if (loader)
-    g_object_unref (loader);
-  if (contents)
-    g_free (contents);
+    g_object_unref_with_context (loader, loader);
+  g_free (contents);
   
   return pixbuf;
 }
Index: gtk/gtkiconview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkiconview.c,v
retrieving revision 1.101
diff -u -p -r1.101 gtkiconview.c
--- gtk/gtkiconview.c	10 Jul 2006 16:59:43 -0000	1.101
+++ gtk/gtkiconview.c	19 Jul 2006 22:42:13 -0000
@@ -948,6 +948,17 @@ gtk_icon_view_destroy (GtkObject *object
     }
 
   remove_scroll_timeout (icon_view);
+
+  if (icon_view->priv->hadjustment != NULL)
+    {
+      g_object_unref_and_context (icon_view->priv->hadjustment);
+      icon_view->priv->hadjustment = NULL;
+    }
+  if (icon_view->priv->vadjustment != NULL)
+    {
+      g_object_unref_and_context (icon_view->priv->vadjustment);
+      icon_view->priv->vadjustment = NULL;
+    }
   
   (* GTK_OBJECT_CLASS (gtk_icon_view_parent_class)->destroy) (object);
 }
@@ -2205,20 +2216,21 @@ gtk_icon_view_set_adjustments (GtkIconVi
     {
       g_signal_handlers_disconnect_matched (icon_view->priv->hadjustment, G_SIGNAL_MATCH_DATA,
 					   0, 0, NULL, NULL, icon_view);
-      g_object_unref (icon_view->priv->hadjustment);
+      g_object_unref_and_context (icon_view->priv->hadjustment);
     }
 
   if (icon_view->priv->vadjustment && (icon_view->priv->vadjustment != vadj))
     {
       g_signal_handlers_disconnect_matched (icon_view->priv->vadjustment, G_SIGNAL_MATCH_DATA,
 					    0, 0, NULL, NULL, icon_view);
-      g_object_unref (icon_view->priv->vadjustment);
+      g_object_unref_and_context (icon_view->priv->vadjustment);
     }
 
   if (icon_view->priv->hadjustment != hadj)
     {
       icon_view->priv->hadjustment = hadj;
-      g_object_ref_sink (icon_view->priv->hadjustment);
+      g_object_ref_sink_with_context (icon_view->priv->hadjustment,
+	  &icon_view->priv->hadjustment);
 
       g_signal_connect (icon_view->priv->hadjustment, "value_changed",
 			G_CALLBACK (gtk_icon_view_adjustment_changed),
@@ -2229,7 +2241,8 @@ gtk_icon_view_set_adjustments (GtkIconVi
   if (icon_view->priv->vadjustment != vadj)
     {
       icon_view->priv->vadjustment = vadj;
-      g_object_ref_sink (icon_view->priv->vadjustment);
+      g_object_ref_sink_with_context (icon_view->priv->vadjustment,
+	  &icon_view->priv->vadjustment);
 
       g_signal_connect (icon_view->priv->vadjustment, "value_changed",
 			G_CALLBACK (gtk_icon_view_adjustment_changed),
@@ -4154,7 +4167,7 @@ free_cell_info (GtkIconViewCellInfo *inf
 {
   free_cell_attributes (info);
 
-  g_object_unref (info->cell);
+  g_object_unref_and_context (info->cell);
   
   if (info->destroy)
     (* info->destroy) (info->func_data);
@@ -4173,10 +4186,9 @@ gtk_icon_view_cell_layout_pack_start (Gt
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
   g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
 
-  g_object_ref_sink (renderer);
 
   info = g_new0 (GtkIconViewCellInfo, 1);
-  info->cell = renderer;
+  info->cell = g_object_ref_sink_with_context (renderer, &info->cell);
   info->expand = expand ? TRUE : FALSE;
   info->pack = GTK_PACK_START;
   info->position = icon_view->priv->n_cells;
@@ -4196,10 +4208,9 @@ gtk_icon_view_cell_layout_pack_end (GtkC
   g_return_if_fail (GTK_IS_CELL_RENDERER (renderer));
   g_return_if_fail (!gtk_icon_view_get_cell_info (icon_view, renderer));
 
-  g_object_ref_sink (renderer);
 
   info = g_new0 (GtkIconViewCellInfo, 1);
-  info->cell = renderer;
+  info->cell = g_object_ref_sink_with_context (renderer, &info->cell);
   info->expand = expand ? TRUE : FALSE;
   info->pack = GTK_PACK_END;
   info->position = icon_view->priv->n_cells;
@@ -4647,7 +4658,7 @@ gtk_icon_view_set_model (GtkIconView *ic
 					    gtk_icon_view_rows_reordered,
 					    icon_view);
 
-      g_object_unref (icon_view->priv->model);
+      g_object_unref_and_context (icon_view->priv->model);
       
       g_list_foreach (icon_view->priv->items, (GFunc)gtk_icon_view_item_free, NULL);
       g_list_free (icon_view->priv->items);
@@ -4663,7 +4674,7 @@ gtk_icon_view_set_model (GtkIconView *ic
 
   if (icon_view->priv->model)
     {
-      g_object_ref (icon_view->priv->model);
+      g_object_ref_and_context (icon_view->priv->model);
       g_signal_connect (icon_view->priv->model,
 			"row_changed",
 			G_CALLBACK (gtk_icon_view_row_changed),
@@ -7931,10 +7942,10 @@ gtk_icon_view_item_accessible_finalize (
     g_object_remove_weak_pointer (G_OBJECT (item->widget), (gpointer) &item->widget);
 
   if (item->state_set)
-    g_object_unref (item->state_set);
+    g_object_unref_and_context (item->state_set);
 
   if (item->text_buffer)
-     g_object_unref (item->text_buffer);
+     g_object_unref_and_context (item->text_buffer);
 
   for (i = 0; i < LAST_ACTION; i++)
     g_free (item->action_descriptions[i]);
@@ -8556,7 +8567,7 @@ gtk_icon_view_accessible_clear_cache (Gt
   while (items)
     {
       info = (GtkIconViewItemAccessibleInfo *) items->data;
-      g_object_unref (info->item);
+      g_object_unref_and_context (info->item);
       g_free (items->data);
       items = items->next;
     }
Index: gtk/gtkimage.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkimage.c,v
retrieving revision 1.77
diff -u -p -r1.77 gtkimage.c
--- gtk/gtkimage.c	18 May 2006 16:50:49 -0000	1.77
+++ gtk/gtkimage.c	19 Jul 2006 22:42:15 -0000
@@ -311,7 +311,7 @@ gtk_image_set_property (GObject      *ob
           mask = g_value_get_object (value);
 
           if (mask)
-            g_object_ref (mask);
+            g_object_ref_with_context (mask, &image->mask);
           
           gtk_image_clear (image);
 
@@ -711,10 +711,10 @@ gtk_image_set_from_pixmap (GtkImage  *im
   g_object_freeze_notify (G_OBJECT (image));
   
   if (pixmap)
-    g_object_ref (pixmap);
+    g_object_ref_with_context (pixmap, &image->data.pixmap.pixmap);
 
   if (mask)
-    g_object_ref (mask);
+    g_object_ref_with_context (mask, &image->mask);
 
   gtk_image_clear (image);
 
@@ -763,10 +763,10 @@ gtk_image_set_from_image  (GtkImage  *im
   g_object_freeze_notify (G_OBJECT (image));
   
   if (gdk_image)
-    g_object_ref (gdk_image);
+    g_object_ref_with_context (gdk_image, &image->data.image.image);
 
   if (mask)
-    g_object_ref (mask);
+    g_object_ref_with_context (mask, &image->mask);
 
   gtk_image_clear (image);
 
@@ -783,7 +783,7 @@ gtk_image_set_from_image  (GtkImage  *im
     {
       /* Clean up the mask if gdk_image was NULL */
       if (mask)
-        g_object_unref (mask);
+        g_object_unref_with_context (mask, &image->mask);
     }
 
   g_object_notify (G_OBJECT (image), "image");
@@ -868,7 +868,7 @@ gtk_image_set_from_pixbuf (GtkImage  *im
   g_object_freeze_notify (G_OBJECT (image));
   
   if (pixbuf)
-    g_object_ref (pixbuf);
+    g_object_ref_with_context (pixbuf, &image->data.pixbuf.pixbuf);
 
   gtk_image_clear (image);
 
@@ -992,7 +992,7 @@ gtk_image_set_from_animation (GtkImage  
   g_object_freeze_notify (G_OBJECT (image));
   
   if (animation)
-    g_object_ref (animation);
+    g_object_ref_with_context (animation, &image->data.anim.anim);
 
   gtk_image_clear (image);
 
@@ -1327,7 +1327,7 @@ gtk_image_reset_anim_iter (GtkImage *ima
 
       if (image->data.anim.iter)
         {
-          g_object_unref (image->data.anim.iter);
+          g_object_unref_with_context (image->data.anim.iter, image->data.anim.iter);
           image->data.anim.iter = NULL;
         }
     }
@@ -1386,7 +1386,7 @@ icon_theme_changed (GtkImage *image)
   if (image->storage_type == GTK_IMAGE_ICON_NAME) 
     {
       if (image->data.name.pixbuf)
-	g_object_unref (image->data.name.pixbuf);
+	g_object_unref_and_context (image->data.name.pixbuf);
       image->data.name.pixbuf = NULL;
 
       gtk_widget_queue_draw (GTK_WIDGET (image));
@@ -1471,6 +1471,9 @@ ensure_pixbuf_for_icon_name (GtkImage *i
 				    image->icon_size,
 				    NULL);
 	}
+      if (image->data.name.pixbuf != NULL)
+	g_object_ref_set_context (image->data.name.pixbuf,
+	    image->data.name.pixbuf, &image->data.name.pixbuf);
     }
 }
 
@@ -1640,7 +1643,7 @@ gtk_image_expose (GtkWidget      *widget
                                            image->icon_size,
                                            NULL);
           if (pixbuf)
-            {              
+            {
               image_bound.width = gdk_pixbuf_get_width (pixbuf);
               image_bound.height = gdk_pixbuf_get_height (pixbuf);
             }
@@ -1797,14 +1800,14 @@ gtk_image_expose (GtkWidget      *widget
                   break;
                 }
             }
-        } /* if rectangle intersects */      
+        } /* if rectangle intersects */
 
       if (mask)
         {
           gdk_gc_set_clip_mask (widget->style->black_gc, NULL);
           gdk_gc_set_clip_origin (widget->style->black_gc, 0, 0);
         }
-      
+
       if (pixbuf)
 	g_object_unref (pixbuf);
 
@@ -1827,7 +1830,7 @@ gtk_image_reset (GtkImage *image)
 
   if (image->mask)
     {
-      g_object_unref (image->mask);
+      g_object_unref_and_context (image->mask);
       image->mask = NULL;
       g_object_notify (G_OBJECT (image), "mask");
     }
@@ -1843,7 +1846,7 @@ gtk_image_reset (GtkImage *image)
     case GTK_IMAGE_PIXMAP:
 
       if (image->data.pixmap.pixmap)
-        g_object_unref (image->data.pixmap.pixmap);
+        g_object_unref_and_context (image->data.pixmap.pixmap);
       image->data.pixmap.pixmap = NULL;
       
       g_object_notify (G_OBJECT (image), "pixmap");
@@ -1853,7 +1856,7 @@ gtk_image_reset (GtkImage *image)
     case GTK_IMAGE_IMAGE:
 
       if (image->data.image.image)
-        g_object_unref (image->data.image.image);
+        g_object_unref_and_context (image->data.image.image);
       image->data.image.image = NULL;
       
       g_object_notify (G_OBJECT (image), "image");
@@ -1863,7 +1866,8 @@ gtk_image_reset (GtkImage *image)
     case GTK_IMAGE_PIXBUF:
 
       if (image->data.pixbuf.pixbuf)
-        g_object_unref (image->data.pixbuf.pixbuf);
+        g_object_unref_and_context (image->data.pixbuf.pixbuf);
+      image->data.pixbuf.pixbuf = NULL;
 
       g_object_notify (G_OBJECT (image), "pixbuf");
       
@@ -1890,7 +1894,7 @@ gtk_image_reset (GtkImage *image)
       gtk_image_reset_anim_iter (image);
       
       if (image->data.anim.anim)
-        g_object_unref (image->data.anim.anim);
+        g_object_unref_and_context (image->data.anim.anim);
       image->data.anim.anim = NULL;
       
       g_object_notify (G_OBJECT (image), "pixbuf-animation");
@@ -1902,7 +1906,7 @@ gtk_image_reset (GtkImage *image)
 	g_free (image->data.name.icon_name);
       image->data.name.icon_name = NULL;
       if (image->data.name.pixbuf)
-	g_object_unref (image->data.name.pixbuf);
+	g_object_unref_and_context (image->data.name.pixbuf);
       image->data.name.pixbuf = NULL;
 
       g_object_notify (G_OBJECT (image), "icon-name");
@@ -2077,7 +2081,7 @@ gtk_image_set_pixel_size (GtkImage *imag
 	{
 	  if (image->data.name.pixbuf)
 	    {
-	      g_object_unref (image->data.name.pixbuf);
+	      g_object_unref_and_context (image->data.name.pixbuf);
 	      image->data.name.pixbuf = NULL;
 	    }
 	  
Index: gtk/gtkimmulticontext.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkimmulticontext.c,v
retrieving revision 1.39
diff -u -p -r1.39 gtkimmulticontext.c
--- gtk/gtkimmulticontext.c	14 May 2006 04:25:29 -0000	1.39
+++ gtk/gtkimmulticontext.c	19 Jul 2006 22:42:16 -0000
@@ -171,7 +171,7 @@ gtk_im_multicontext_set_slave (GtkIMMult
 					    gtk_im_multicontext_commit_cb,
 					    multicontext);
 
-      g_object_unref (multicontext->slave);
+      g_object_unref_and_context (multicontext->slave);
       multicontext->slave = NULL;
 
       if (!finalizing)
@@ -182,7 +182,7 @@ gtk_im_multicontext_set_slave (GtkIMMult
 
   if (multicontext->slave)
     {
-      g_object_ref (multicontext->slave);
+      g_object_ref_and_context (multicontext->slave);
 
       g_signal_connect (multicontext->slave, "preedit_start",
 			G_CALLBACK (gtk_im_multicontext_preedit_start_cb),
Index: gtk/gtkinvisible.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkinvisible.c,v
retrieving revision 1.33
diff -u -p -r1.33 gtkinvisible.c
--- gtk/gtkinvisible.c	25 May 2006 05:30:14 -0000	1.33
+++ gtk/gtkinvisible.c	19 Jul 2006 22:42:16 -0000
@@ -37,6 +37,7 @@ enum {
   LAST_ARG
 };
 
+static void gtk_invisible_finalize      (GObject           *object);
 static void gtk_invisible_destroy       (GtkObject         *object);
 static void gtk_invisible_realize       (GtkWidget         *widget);
 static void gtk_invisible_style_set     (GtkWidget         *widget,
@@ -79,6 +80,7 @@ gtk_invisible_class_init (GtkInvisibleCl
   gobject_class->set_property = gtk_invisible_set_property;
   gobject_class->get_property = gtk_invisible_get_property;
   gobject_class->constructor = gtk_invisible_constructor;
+  gobject_class->finalize = gtk_invisible_finalize;
 
   g_object_class_install_property (gobject_class,
 				   PROP_SCREEN,
@@ -100,7 +102,7 @@ gtk_invisible_init (GtkInvisible *invisi
   g_object_ref_sink (invisible);
 
   invisible->has_user_ref_count = TRUE;
-  invisible->screen = gdk_screen_get_default ();
+  invisible->screen = g_object_ref_with_context (gdk_screen_get_default (), &invisible->screen);
   
   colormap = _gtk_widget_peek_colormap ();
   if (colormap)
@@ -121,6 +123,17 @@ gtk_invisible_destroy (GtkObject *object
   GTK_OBJECT_CLASS (gtk_invisible_parent_class)->destroy (object);  
 }
 
+static void
+gtk_invisible_finalize (GObject *object)
+{
+  GtkInvisible *invisible = GTK_INVISIBLE (object);
+
+  if (invisible->screen)
+    g_object_unref_and_context (invisible->screen);
+  
+  G_OBJECT_CLASS (gtk_invisible_parent_class)->finalize (object);  
+}
+
 /**
  * gtk_invisible_new_for_screen:
  * @screen: a #GdkScreen which identifies on which
@@ -184,9 +197,9 @@ gtk_invisible_set_screen (GtkInvisible *
   if (was_realized)
     gtk_widget_unrealize (widget);
   
-  invisible->screen = screen;
-  if (screen != previous_screen)
-    _gtk_widget_propagate_screen_changed (widget, previous_screen);
+  invisible->screen = g_object_ref_with_context (screen, &invisible->screen);
+  _gtk_widget_propagate_screen_changed (widget, previous_screen);
+  g_object_unref_with_context (previous_screen, &invisible->screen);
   g_object_notify (G_OBJECT (invisible), "screen");
   
   if (was_realized)
@@ -236,7 +249,6 @@ gtk_invisible_realize (GtkWidget *widget
   attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_NOREDIR;
 
   widget->window = gdk_window_new (parent, &attributes, attributes_mask);
-					      
   gdk_window_set_user_data (widget->window, widget);
   
   widget->style = gtk_style_attach (widget->style, widget->window);
Index: gtk/gtkitemfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkitemfactory.c,v
retrieving revision 1.91
diff -u -p -r1.91 gtkitemfactory.c
--- gtk/gtkitemfactory.c	28 Jun 2006 16:09:17 -0000	1.91
+++ gtk/gtkitemfactory.c	19 Jul 2006 22:42:17 -0000
@@ -204,6 +204,13 @@ gtk_item_factory_item_remove_widget (Gtk
   g_object_set_qdata (G_OBJECT (widget), quark_item_path, NULL);
 }
 
+
+static void
+accel_unref (gpointer accel)
+{
+  g_object_unref_with_context (accel, &accel_unref);
+}
+
 /**
  * gtk_item_factory_add_foreign:
  * @accel_widget:     widget to install an accelerator on 
@@ -265,11 +272,11 @@ gtk_item_factory_add_foreign (GtkWidget 
   gtk_widget_set_name (accel_widget, item->path);
   if (accel_group)
     {
-      g_object_ref (accel_group);
+      g_object_ref_with_context (accel_group, &accel_unref);
       g_object_set_qdata_full (G_OBJECT (accel_widget),
 			       quark_accel_group,
 			       accel_group,
-			       g_object_unref);
+			       accel_unref);
     }
   else
     g_object_set_qdata (G_OBJECT (accel_widget), quark_accel_group, NULL);
@@ -402,7 +409,7 @@ gtk_item_factory_construct (GtkItemFacto
   if (accel_group)
     {
       ifactory->accel_group = accel_group;
-      g_object_ref (ifactory->accel_group);
+      g_object_ref_and_context (ifactory->accel_group);
     }
   else
     ifactory->accel_group = gtk_accel_group_new ();
@@ -484,9 +491,9 @@ gtk_item_factory_destroy (GtkObject *obj
 
       dobj = GTK_OBJECT (ifactory->widget);
 
-      g_object_ref_sink (dobj);
+      g_object_ref_sink_and_context (dobj);
       gtk_object_destroy (dobj);
-      g_object_unref (dobj);
+      g_object_unref_and_context (dobj);
 
       ifactory->widget = NULL;
     }
@@ -515,7 +522,7 @@ gtk_item_factory_finalize (GObject *obje
 
   ifactory = GTK_ITEM_FACTORY (object);
 
-  g_object_unref (ifactory->accel_group);
+  g_object_unref_and_context (ifactory->accel_group);
   g_free (ifactory->path);
   g_assert (ifactory->widget == NULL);
 
@@ -1271,7 +1278,7 @@ gtk_item_factories_path_delete (const gc
 
 	  widget = slist->data;
 	  widget_list = g_slist_prepend (widget_list, widget);
-	  g_object_ref (widget);
+	  g_object_ref_with_context (widget, &slist->data);
 	}
 
       for (slist = widget_list; slist; slist = slist->next)
@@ -1280,7 +1287,7 @@ gtk_item_factories_path_delete (const gc
 
 	  widget = slist->data;
 	  gtk_widget_destroy (widget);
-	  g_object_unref (widget);
+	  g_object_unref_with_context (widget, &slist->data);
 	}
       g_slist_free (widget_list);
     }
Index: gtk/gtkkeyhash.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkkeyhash.c,v
retrieving revision 1.15
diff -u -p -r1.15 gtkkeyhash.c
--- gtk/gtkkeyhash.c	4 Jan 2006 07:06:12 -0000	1.15
+++ gtk/gtkkeyhash.c	19 Jul 2006 22:42:18 -0000
@@ -127,7 +127,7 @@ _gtk_key_hash_new (GdkKeymap      *keyma
 {
   GtkKeyHash *key_hash = g_new (GtkKeyHash, 1);
 
-  key_hash->keymap = keymap;
+  key_hash->keymap = g_object_ref_with_context (keymap, &key_hash->keymap);;
   g_signal_connect (keymap, "keys_changed",
 		    G_CALLBACK (key_hash_keys_changed), key_hash);
 
@@ -183,6 +183,8 @@ _gtk_key_hash_free (GtkKeyHash *key_hash
 
   g_list_foreach (key_hash->entries_list, key_hash_free_entry_foreach, key_hash);
   g_list_free (key_hash->entries_list);
+
+  g_object_unref_and_context (key_hash->keymap);
   
   g_free (key_hash);
 }
Index: gtk/gtkmain.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmain.c,v
retrieving revision 1.279
diff -u -p -r1.279 gtkmain.c
--- gtk/gtkmain.c	21 Jun 2006 18:16:55 -0000	1.279
+++ gtk/gtkmain.c	19 Jul 2006 22:42:20 -0000
@@ -1163,8 +1163,8 @@ rewrite_event_for_window (GdkEvent  *eve
       return event;
     }
 
-  g_object_unref (event->any.window);
-  event->any.window = g_object_ref (new_window);
+  g_object_unref_and_context (event->any.window);
+  event->any.window = g_object_ref_with_context (new_window, &event->any.window);
 
   return event;
 }
@@ -1351,11 +1351,11 @@ gtk_main_do_event (GdkEvent *event)
       break;
       
     case GDK_DELETE:
-      g_object_ref (event_widget);
+      g_object_ref_and_context (event_widget);
       if ((!window_group->grabs || gtk_widget_get_toplevel (window_group->grabs->data) == event_widget) &&
 	  !gtk_widget_event (event_widget, event))
 	gtk_widget_destroy (event_widget);
-      g_object_unref (event_widget);
+      g_object_unref_and_context (event_widget);
       break;
       
     case GDK_DESTROY:
@@ -1364,11 +1364,11 @@ gtk_main_do_event (GdkEvent *event)
        */
       if (!event_widget->parent)
 	{
-	  g_object_ref (event_widget);
+	  g_object_ref_and_context (event_widget);
 	  if (!gtk_widget_event (event_widget, event) &&
 	      GTK_WIDGET_REALIZED (event_widget))
 	    gtk_widget_destroy (event_widget);
-	  g_object_unref (event_widget);
+	  g_object_unref_and_context (event_widget);
 	}
       break;
       
@@ -1424,13 +1424,13 @@ gtk_main_do_event (GdkEvent *event)
     case GDK_ENTER_NOTIFY:
       if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
 	{
-	  g_object_ref (event_widget);
+	  g_object_ref_and_context (event_widget);
 	  
 	  gtk_widget_event (grab_widget, event);
 	  if (event_widget == grab_widget)
 	    GTK_PRIVATE_SET_FLAG (event_widget, GTK_LEAVE_PENDING);
 	  
-	  g_object_unref (event_widget);
+	  g_object_unref_and_context (event_widget);
 	}
       break;
       
@@ -1519,7 +1519,7 @@ gtk_grab_notify_foreach (GtkWidget *chil
   was_shadowed = info->old_grab_widget && !info->was_grabbed;
   is_shadowed = info->new_grab_widget && !info->is_grabbed;
 
-  g_object_ref (child);
+  g_object_ref_and_context (child);
   
   if (was_shadowed != is_shadowed)
     _gtk_widget_grab_notify (child, was_shadowed);
@@ -1527,13 +1527,18 @@ gtk_grab_notify_foreach (GtkWidget *chil
   if ((was_shadowed || is_shadowed) && GTK_IS_CONTAINER (child))
     gtk_container_forall (GTK_CONTAINER (child), gtk_grab_notify_foreach, info);
       
-  g_object_unref (child);
+  g_object_unref_and_context (child);
   
   info->was_grabbed = was_grabbed;
   info->is_grabbed = is_grabbed;
 }
 
 static void
+grab_ref_with_context (gpointer ptr, gpointer ctx)
+{
+  g_object_ref_with_context (ptr, ctx);
+}
+static void
 gtk_grab_notify (GtkWindowGroup *group,
 		 GtkWidget      *old_grab_widget,
 		 GtkWidget      *new_grab_widget)
@@ -1547,10 +1552,10 @@ gtk_grab_notify (GtkWindowGroup *group,
   info.old_grab_widget = old_grab_widget;
   info.new_grab_widget = new_grab_widget;
 
-  g_object_ref (group);
+  g_object_ref_and_context (group);
 
   toplevels = gtk_window_list_toplevels ();
-  g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
+  g_list_foreach (toplevels, grab_ref_with_context, &toplevels);
 			    
   while (toplevels)
     {
@@ -1562,10 +1567,10 @@ gtk_grab_notify (GtkWindowGroup *group,
 
       if (group == gtk_window_get_group (toplevel))
 	gtk_grab_notify_foreach (GTK_WIDGET (toplevel), &info);
-      g_object_unref (toplevel);
+      g_object_unref_with_context (toplevel, &toplevels);
     }
 
-  g_object_unref (group);
+  g_object_unref_and_context (group);
 }
 
 void
@@ -1587,7 +1592,7 @@ gtk_grab_add (GtkWidget *widget)
       else
 	old_grab_widget = NULL;
 
-      g_object_ref (widget);
+      g_object_ref_with_context (widget, group);
       group->grabs = g_slist_prepend (group->grabs, widget);
 
       gtk_grab_notify (group, old_grab_widget, widget);
@@ -1628,7 +1633,7 @@ gtk_grab_remove (GtkWidget *widget)
 
       gtk_grab_notify (group, widget, new_grab_widget);
       
-      g_object_unref (widget);
+      g_object_unref_with_context (widget, group);
     }
 }
 
@@ -2131,7 +2136,7 @@ gtk_propagate_event (GtkWidget *widget,
   
   handled_event = FALSE;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
       
   if ((event->type == GDK_KEY_PRESS) ||
       (event->type == GDK_KEY_RELEASE))
@@ -2187,18 +2192,18 @@ gtk_propagate_event (GtkWidget *widget,
 	    handled_event = gtk_widget_event (widget, event);
 	      
 	  tmp = widget->parent;
-	  g_object_unref (widget);
+	  g_object_unref_and_context (widget);
 
 	  widget = tmp;
 	  
 	  if (!handled_event && widget)
-	    g_object_ref (widget);
+	    g_object_ref_and_context (widget);
 	  else
 	    break;
 	}
     }
   else
-    g_object_unref (widget);
+    g_object_unref_and_context (widget);
 }
 
 #if 0
Index: gtk/gtkmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenu.c,v
retrieving revision 1.222
diff -u -p -r1.222 gtkmenu.c
--- gtk/gtkmenu.c	3 Jul 2006 00:25:05 -0000	1.222
+++ gtk/gtkmenu.c	19 Jul 2006 22:42:24 -0000
@@ -184,7 +184,7 @@ static void     gtk_menu_grab_notify    
 					    gboolean          was_grabbed);
 
 static void     gtk_menu_stop_scrolling         (GtkMenu  *menu);
-static void     gtk_menu_remove_scroll_timeout  (GtkMenu  *menu);
+static gboolean gtk_menu_remove_scroll_timeout  (GtkMenu  *menu);
 static gboolean gtk_menu_scroll_timeout         (gpointer  data);
 static gboolean gtk_menu_scroll_timeout_initial (gpointer  data);
 static void     gtk_menu_start_scrolling        (GtkMenu  *menu);
@@ -803,8 +803,8 @@ gtk_menu_window_event (GtkWidget *window
 {
   gboolean handled = FALSE;
 
-  g_object_ref (window);
-  g_object_ref (menu);
+  g_object_ref_and_context (window);
+  g_object_ref_and_context (menu);
 
   switch (event->type)
     {
@@ -816,8 +816,8 @@ gtk_menu_window_event (GtkWidget *window
       break;
     }
 
-  g_object_unref (window);
-  g_object_unref (menu);
+  g_object_unref_and_context (window);
+  g_object_unref_and_context (menu);
 
   return handled;
 }
@@ -920,7 +920,7 @@ gtk_menu_destroy (GtkObject *object)
 
   if (menu->old_active_menu_item)
     {
-      g_object_unref (menu->old_active_menu_item);
+      g_object_unref_and_context (menu->old_active_menu_item);
       menu->old_active_menu_item = NULL;
     }
 
@@ -933,7 +933,7 @@ gtk_menu_destroy (GtkObject *object)
   
   if (menu->accel_group)
     {
-      g_object_unref (menu->accel_group);
+      g_object_unref_and_context (menu->accel_group);
       menu->accel_group = NULL;
     }
 
@@ -1026,9 +1026,9 @@ gtk_menu_attach_to_widget (GtkMenu	     
      return;
     }
   
-  g_object_ref_sink (menu);
   
   data = g_new (GtkMenuAttachData, 1);
+  g_object_ref_sink_with_context (menu, &data->attach_widget);
   data->attach_widget = attach_widget;
   
   g_signal_connect (attach_widget, "screen_changed",
@@ -1107,7 +1107,7 @@ gtk_menu_detach (GtkMenu *menu)
   /* Fallback title for menu comes from attach widget */
   gtk_menu_update_title (menu);
 
-  g_object_unref (menu);
+  g_object_unref_with_context (menu, &data->attach_widget);
 }
 
 static void
@@ -1125,7 +1125,7 @@ gtk_menu_remove (GtkContainer *container
    */
   if (menu->old_active_menu_item == widget)
     {
-      g_object_unref (menu->old_active_menu_item);
+      g_object_unref_and_context (menu->old_active_menu_item);
       menu->old_active_menu_item = NULL;
     }
 
@@ -1193,14 +1193,14 @@ gtk_menu_tearoff_bg_copy (GtkMenu *menu)
       gdk_draw_drawable (pixmap, gc,
 			 menu->tearoff_window->window,
 			 0, 0, 0, 0, -1, -1);
-      g_object_unref (gc);
+      g_object_unref_with_context (gc, gc);
 
       gtk_widget_set_size_request (menu->tearoff_window,
 				   width,
 				   height);
 
       gdk_window_set_back_pixmap (menu->tearoff_window->window, pixmap, FALSE);
-      g_object_unref (pixmap);
+      g_object_unref_with_context (pixmap, pixmap);
     }
 }
 
@@ -1463,9 +1463,9 @@ gtk_menu_popdown (GtkMenu *menu)
   if (menu_shell->active_menu_item)
     {
       if (menu->old_active_menu_item)
-	g_object_unref (menu->old_active_menu_item);
+	g_object_unref_and_context (menu->old_active_menu_item);
       menu->old_active_menu_item = menu_shell->active_menu_item;
-      g_object_ref (menu->old_active_menu_item);
+      g_object_ref_and_context (menu->old_active_menu_item);
     }
 
   gtk_menu_shell_deselect (menu_shell);
@@ -1539,7 +1539,7 @@ gtk_menu_get_active (GtkMenu *menu)
       
       menu->old_active_menu_item = child;
       if (menu->old_active_menu_item)
-	g_object_ref (menu->old_active_menu_item);
+	g_object_ref_and_context (menu->old_active_menu_item);
     }
   
   return menu->old_active_menu_item;
@@ -1561,9 +1561,9 @@ gtk_menu_set_active (GtkMenu *menu,
       if (GTK_BIN (child)->child)
 	{
 	  if (menu->old_active_menu_item)
-	    g_object_unref (menu->old_active_menu_item);
+	    g_object_unref_and_context (menu->old_active_menu_item);
 	  menu->old_active_menu_item = child;
-	  g_object_ref (menu->old_active_menu_item);
+	  g_object_ref_and_context (menu->old_active_menu_item);
 	}
     }
 }
@@ -1577,10 +1577,10 @@ gtk_menu_set_accel_group (GtkMenu	*menu,
   if (menu->accel_group != accel_group)
     {
       if (menu->accel_group)
-	g_object_unref (menu->accel_group);
+	g_object_unref_and_context (menu->accel_group);
       menu->accel_group = accel_group;
       if (menu->accel_group)
-	g_object_ref (menu->accel_group);
+	g_object_ref_and_context (menu->accel_group);
       _gtk_menu_refresh_accel_paths (menu, TRUE);
     }
 }
@@ -2895,7 +2895,7 @@ gtk_menu_motion_notify  (GtkWidget	   *w
 	  GdkEvent *send_event = gdk_event_new (GDK_ENTER_NOTIFY);
 	  gboolean result;
 
-	  send_event->crossing.window = g_object_ref (event->window);
+	  send_event->crossing.window = g_object_ref_with_context (event->window, &send_event->crossing.window);
 	  send_event->crossing.time = event->time;
 	  send_event->crossing.send_event = TRUE;
 	  send_event->crossing.x_root = event->x_root;
@@ -3496,7 +3496,7 @@ gtk_menu_stop_navigating_submenu_cb (gpo
 	{
 	  GdkEvent *send_event = gdk_event_new (GDK_ENTER_NOTIFY);
 
-	  send_event->crossing.window = g_object_ref (child_window);
+	  send_event->crossing.window = g_object_ref_with_context (child_window, &send_event->crossing.window);
 	  send_event->crossing.time = GDK_CURRENT_TIME; /* Bogus */
 	  send_event->crossing.send_event = TRUE;
 
@@ -3556,7 +3556,7 @@ draw_stay_up_triangle (GdkWindow *window
                      clipbox.x, clipbox.y,
                      clipbox.width, clipbox.height);
   
-  g_object_unref (ugly_gc);
+  g_object_unref_with_context (ugly_gc, ugly_gc);
 }
 #endif
 
@@ -3941,32 +3941,38 @@ gtk_menu_position (GtkMenu *menu)
   menu->scroll_offset = scroll_offset;
 }
 
-static void
+static gboolean
 gtk_menu_remove_scroll_timeout (GtkMenu *menu)
 {
+  gboolean was_scrolling = FALSE;
+
   if (menu->timeout_id)
     {
       g_source_remove (menu->timeout_id);
       menu->timeout_id = 0;
+      was_scrolling = TRUE;
     }
+
+  return was_scrolling;
 }
 
 static void
 gtk_menu_stop_scrolling (GtkMenu *menu)
 {
-  GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
-  gboolean touchscreen_mode;
-
-  gtk_menu_remove_scroll_timeout (menu);
-
-  g_object_get (G_OBJECT (settings),
-                "gtk-touchscreen-mode", &touchscreen_mode,
-                NULL);
-
-  if (!touchscreen_mode)
+  if (gtk_menu_remove_scroll_timeout (menu))
     {
-      menu->upper_arrow_prelight = FALSE;
-      menu->lower_arrow_prelight = FALSE;
+      GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (menu));
+      gboolean touchscreen_mode;
+
+      g_object_get (G_OBJECT (settings),
+	  "gtk-touchscreen-mode", &touchscreen_mode,
+	  NULL);
+
+      if (!touchscreen_mode)
+      {
+	menu->upper_arrow_prelight = FALSE;
+	menu->lower_arrow_prelight = FALSE;
+      }
     }
 }
 
@@ -4309,22 +4315,25 @@ gtk_menu_reparent (GtkMenu      *menu, 
   GtkWidget *widget = GTK_WIDGET (menu);
   gboolean was_floating = g_object_is_floating (object);
 
-  g_object_ref_sink (object);
+  g_object_ref_sink_and_context (object);
 
   if (unrealize)
     {
-      g_object_ref (object);
+      g_object_ref_and_context (object);
       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
       gtk_container_add (GTK_CONTAINER (new_parent), widget);
-      g_object_unref (object);
+      g_object_unref_and_context (object);
     }
   else
     gtk_widget_reparent (GTK_WIDGET (menu), new_parent);
   
   if (was_floating)
-    g_object_force_floating (G_OBJECT (object));
+    {
+      g_object_force_floating (G_OBJECT (object));
+      g_object_ref_set_context (object, &object, object);
+    }
   else
-    g_object_unref (object);
+    g_object_unref_and_context (object);
 }
 
 static void
Index: gtk/gtkmenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenuitem.c,v
retrieving revision 1.132
diff -u -p -r1.132 gtkmenuitem.c
--- gtk/gtkmenuitem.c	9 Jun 2006 15:20:53 -0000	1.132
+++ gtk/gtkmenuitem.c	19 Jul 2006 22:42:26 -0000
@@ -656,7 +656,7 @@ gtk_menu_item_realize (GtkWidget *widget
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   attributes.x = widget->allocation.x;
   attributes.y = widget->allocation.y;
Index: gtk/gtkmenushell.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenushell.c,v
retrieving revision 1.101
diff -u -p -r1.101 gtkmenushell.c
--- gtk/gtkmenushell.c	14 May 2006 04:25:29 -0000	1.101
+++ gtk/gtkmenushell.c	19 Jul 2006 22:42:27 -0000
@@ -997,8 +997,8 @@ gtk_menu_shell_activate_item (GtkMenuShe
   if (!deactivate)
     deactivate = GTK_MENU_ITEM_GET_CLASS (menu_item)->hide_on_activate;
 
-  g_object_ref (menu_shell);
-  g_object_ref (menu_item);
+  g_object_ref_and_context (menu_shell);
+  g_object_ref_and_context (menu_item);
 
   if (deactivate)
     {
@@ -1006,7 +1006,7 @@ gtk_menu_shell_activate_item (GtkMenuShe
 
       do
 	{
-	  g_object_ref (parent_menu_shell);
+	  g_object_ref_with_context (parent_menu_shell, gtk_menu_shell_activate_item);
 	  shells = g_slist_prepend (shells, parent_menu_shell);
 	  parent_menu_shell = (GtkMenuShell*) parent_menu_shell->parent_menu_shell;
 	}
@@ -1026,12 +1026,12 @@ gtk_menu_shell_activate_item (GtkMenuShe
   for (slist = shells; slist; slist = slist->next)
     {
       g_signal_emit (slist->data, menu_shell_signals[SELECTION_DONE], 0);
-      g_object_unref (slist->data);
+      g_object_unref_with_context (slist->data, gtk_menu_shell_activate_item);
     }
   g_slist_free (shells);
 
-  g_object_unref (menu_shell);
-  g_object_unref (menu_item);
+  g_object_unref_and_context (menu_shell);
+  g_object_unref_and_context (menu_item);
 }
 
 /* Distance should be +/- 1 */
Index: gtk/gtkmenutoolbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmenutoolbutton.c,v
retrieving revision 1.25
diff -u -p -r1.25 gtkmenutoolbutton.c
--- gtk/gtkmenutoolbutton.c	14 May 2006 04:25:29 -0000	1.25
+++ gtk/gtkmenutoolbutton.c	19 Jul 2006 22:42:28 -0000
@@ -103,21 +103,21 @@ gtk_menu_tool_button_construct_contents 
 
   if (priv->button && priv->button->parent)
     {
-      g_object_ref (priv->button);
+      g_object_ref_and_context (priv->button);
       gtk_container_remove (GTK_CONTAINER (priv->button->parent),
                             priv->button);
       gtk_container_add (GTK_CONTAINER (box), priv->button);
-      g_object_unref (priv->button);
+      g_object_unref_and_context (priv->button);
     }
 
   if (priv->arrow_button && priv->arrow_button->parent)
     {
-      g_object_ref (priv->arrow_button);
+      g_object_ref_and_context (priv->arrow_button);
       gtk_container_remove (GTK_CONTAINER (priv->arrow_button->parent),
                             priv->arrow_button);
       gtk_box_pack_end (GTK_BOX (box), priv->arrow_button,
                         FALSE, FALSE, 0);
-      g_object_unref (priv->arrow_button);
+      g_object_unref_and_context (priv->arrow_button);
     }
 
   if (priv->box)
@@ -377,10 +377,10 @@ gtk_menu_tool_button_init (GtkMenuToolBu
   box = gtk_hbox_new (FALSE, 0);
 
   real_button = GTK_BIN (button)->child;
-  g_object_ref (real_button);
+  g_object_ref_and_context (real_button);
   gtk_container_remove (GTK_CONTAINER (button), real_button);
   gtk_container_add (GTK_CONTAINER (box), real_button);
-  g_object_unref (real_button);
+  g_object_unref_and_context (real_button);
 
   arrow_button = gtk_toggle_button_new ();
   arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
Index: gtk/gtkmisc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmisc.c,v
retrieving revision 1.39
diff -u -p -r1.39 gtkmisc.c
--- gtk/gtkmisc.c	14 May 2006 04:25:29 -0000	1.39
+++ gtk/gtkmisc.c	19 Jul 2006 22:42:28 -0000
@@ -314,7 +314,7 @@ gtk_misc_realize (GtkWidget *widget)
   if (GTK_WIDGET_NO_WINDOW (widget))
     {
       widget->window = gtk_widget_get_parent_window (widget);
-      g_object_ref (widget->window);
+      g_object_ref_and_context (widget->window);
       widget->style = gtk_style_attach (widget->style, widget->window);
     }
   else
Index: gtk/gtknotebook.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtknotebook.c,v
retrieving revision 1.220
diff -u -p -r1.220 gtknotebook.c
--- gtk/gtknotebook.c	17 Jul 2006 17:22:31 -0000	1.220
+++ gtk/gtknotebook.c	19 Jul 2006 22:42:35 -0000
@@ -1171,13 +1171,13 @@ gtk_notebook_move_focus_out (GtkNotebook
   if (!GTK_WIDGET_TOPLEVEL (toplevel))
     return;
 
-  g_object_ref (notebook);
+  g_object_ref_and_context (notebook);
   
   notebook->focus_out = TRUE;
   g_signal_emit_by_name (toplevel, "move_focus", direction_type);
   notebook->focus_out = FALSE;
   
-  g_object_unref (notebook);
+  g_object_unref_and_context (notebook);
 }
 
 static gint
@@ -1586,7 +1586,7 @@ gtk_notebook_realize (GtkWidget *widget)
   gtk_notebook_get_event_window_position (notebook, &event_window_pos);
   
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.x = event_window_pos.x;
@@ -2531,11 +2531,11 @@ show_drag_window (GtkNotebook        *no
       gdk_window_set_user_data (priv->drag_window, widget);
     }
 
-  g_object_ref (page->tab_label);
+  g_object_ref_and_context (page->tab_label);
   gtk_widget_unparent (page->tab_label);
   gtk_widget_set_parent_window (page->tab_label, priv->drag_window);
   gtk_widget_set_parent (page->tab_label, widget);
-  g_object_unref (page->tab_label);
+  g_object_unref_and_context (page->tab_label);
 
   gdk_window_show (priv->drag_window);
 
@@ -2560,7 +2560,7 @@ hide_drag_window (GtkNotebook        *no
   if (page->tab_label->window != widget->window ||
       !NOTEBOOK_IS_TAB_LABEL_PARENT (notebook, page))
     {
-      g_object_ref (page->tab_label);
+      g_object_ref_and_context (page->tab_label);
 
       if (GTK_IS_WINDOW (parent))
 	{
@@ -2572,7 +2572,7 @@ hide_drag_window (GtkNotebook        *no
 
       gtk_widget_set_parent_window (page->tab_label, widget->window);
       gtk_widget_set_parent (page->tab_label, widget);
-      g_object_unref (page->tab_label);
+      g_object_unref_and_context (page->tab_label);
     }
 
   if (priv->drag_window &&
@@ -3053,7 +3053,7 @@ gtk_notebook_drag_begin (GtkWidget      
   tab_label = priv->detached_tab->tab_label;
 
   hide_drag_window (notebook, priv, notebook->cur_page);
-  g_object_ref (tab_label);
+  g_object_ref_and_context (tab_label);
   gtk_widget_unparent (tab_label);
 
   priv->dnd_window = gtk_window_new (GTK_WINDOW_POPUP);
@@ -3061,7 +3061,7 @@ gtk_notebook_drag_begin (GtkWidget      
   gtk_widget_set_size_request (priv->dnd_window,
 			       priv->detached_tab->allocation.width,
 			       priv->detached_tab->allocation.height);
-  g_object_unref (tab_label);
+  g_object_unref_and_context (tab_label);
 
   g_signal_connect (G_OBJECT (priv->dnd_window), "expose-event",
 		    G_CALLBACK (on_drag_icon_expose), notebook);
@@ -3257,14 +3257,14 @@ do_detach_tab (GtkNotebook     *from,
   menu_label = gtk_notebook_get_menu_label (from, child);
 
   if (menu_label)
-    g_object_ref (menu_label);
+    g_object_ref_and_context (menu_label);
 
   tab_label = gtk_notebook_get_tab_label (from, child);
   
   if (tab_label)
-    g_object_ref (tab_label);
+    g_object_ref_and_context (tab_label);
 
-  g_object_ref (child);
+  g_object_ref_and_context (child);
 
   gtk_container_child_get (GTK_CONTAINER (from),
 			   child,
@@ -3293,13 +3293,13 @@ do_detach_tab (GtkNotebook     *from,
 			   "detachable", detachable,
 			   NULL);
   if (child)
-    g_object_unref (child);
+    g_object_unref_and_context (child);
 
   if (tab_label)
-    g_object_unref (tab_label);
+    g_object_unref_and_context (tab_label);
 
   if (menu_label)
-    g_object_unref (menu_label);
+    g_object_unref_and_context (menu_label);
 
   gtk_notebook_set_current_page (to, page_num);
 }
@@ -3568,7 +3568,7 @@ gtk_notebook_remove (GtkContainer *conta
   if (children == NULL)
     return;
   
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
 
   gtk_notebook_real_remove (notebook, children);
 
@@ -3578,7 +3578,7 @@ gtk_notebook_remove (GtkContainer *conta
 		 widget,
 		 page_num);
   
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 static gboolean
@@ -4580,7 +4580,7 @@ gtk_notebook_draw_tab (GtkNotebook     *
           GdkEvent *expose_event = gdk_event_new (GDK_EXPOSE);
 
           /* This is a lame hack since all this code needs rewriting anyhow */
-          expose_event->expose.window = g_object_ref (page->tab_label->window);
+          expose_event->expose.window = g_object_ref_with_context (page->tab_label->window, &expose_event->expose.window);
           expose_event->expose.area = child_area;
           expose_event->expose.region = gdk_region_rectangle (&child_area);
           expose_event->expose.send_event = TRUE;
Index: gtk/gtkoldeditable.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoldeditable.c,v
retrieving revision 1.31
diff -u -p -r1.31 gtkoldeditable.c
--- gtk/gtkoldeditable.c	14 May 2006 04:25:29 -0000	1.31
+++ gtk/gtkoldeditable.c	19 Jul 2006 22:42:36 -0000
@@ -673,7 +673,7 @@ old_editable_text_received_cb (GtkClipbo
   GtkOldEditable *old_editable = GTK_OLD_EDITABLE (data);
 
   gtk_old_editable_paste_received (old_editable, text, TRUE);
-  g_object_unref (G_OBJECT (old_editable));
+  g_object_unref_with_context (old_editable, old_editable_text_received_cb);
 }
 
 /**
@@ -791,7 +791,7 @@ gtk_old_editable_real_paste_clipboard (G
   GtkClipboard *clipboard = gtk_widget_get_clipboard (GTK_WIDGET (old_editable), 
 						      GDK_SELECTION_CLIPBOARD);
 
-  g_object_ref (G_OBJECT (old_editable));
+  g_object_ref_with_context (old_editable, old_editable_text_received_cb);
   gtk_clipboard_request_text (clipboard, old_editable_text_received_cb, old_editable);
 }
 
Index: gtk/gtkoptionmenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkoptionmenu.c,v
retrieving revision 1.86
diff -u -p -r1.86 gtkoptionmenu.c
--- gtk/gtkoptionmenu.c	6 Jul 2006 05:14:01 -0000	1.86
+++ gtk/gtkoptionmenu.c	19 Jul 2006 22:42:37 -0000
@@ -747,10 +747,10 @@ gtk_option_menu_item_destroy_cb (GtkWidg
 
   if (child)
     {
-      g_object_ref (child);
+      g_object_ref_and_context (child);
       gtk_option_menu_remove_contents (option_menu);
       gtk_widget_destroy (child);
-      g_object_unref (child);
+      g_object_unref_and_context (child);
 
       gtk_option_menu_select_first_sensitive (option_menu);
     }
Index: gtk/gtkpaned.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpaned.c,v
retrieving revision 1.86
diff -u -p -r1.86 gtkpaned.c
--- gtk/gtkpaned.c	19 May 2006 20:32:28 -0000	1.86
+++ gtk/gtkpaned.c	19 Jul 2006 22:42:38 -0000
@@ -630,7 +630,7 @@ gtk_paned_realize (GtkWidget *widget)
   paned = GTK_PANED (widget);
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.wclass = GDK_INPUT_ONLY;
Index: gtk/gtkpathbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkpathbar.c,v
retrieving revision 1.56
diff -u -p -r1.56 gtkpathbar.c
--- gtk/gtkpathbar.c	6 Jul 2006 05:14:01 -0000	1.56
+++ gtk/gtkpathbar.c	19 Jul 2006 22:42:40 -0000
@@ -226,7 +226,7 @@ gtk_path_bar_finalize (GObject *object)
     g_object_unref (path_bar->desktop_icon);
 
   if (path_bar->file_system)
-    g_object_unref (path_bar->file_system);
+    g_object_unref_and_context (path_bar->file_system);
 
   G_OBJECT_CLASS (gtk_path_bar_parent_class)->finalize (object);
 }
@@ -1579,7 +1579,7 @@ _gtk_path_bar_set_file_system (GtkPathBa
 
   g_assert (path_bar->file_system == NULL);
 
-  path_bar->file_system = g_object_ref (file_system);
+  path_bar->file_system = g_object_ref_with_context (file_system, &path_bar->file_system);
 
   home = g_get_home_dir ();
   if (home != NULL)
Index: gtk/gtkplug-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkplug-x11.c,v
retrieving revision 1.2
diff -u -p -r1.2 gtkplug-x11.c
--- gtk/gtkplug-x11.c	13 Sep 2005 19:57:41 -0000	1.2
+++ gtk/gtkplug-x11.c	19 Jul 2006 22:42:40 -0000
@@ -245,7 +245,7 @@ _gtk_plug_windowing_filter_func (GdkXEve
 
 	return_val = GDK_FILTER_REMOVE;
 	
-	g_object_ref (plug);
+	g_object_ref_and_context (plug);
 	
 	if (was_embedded)
 	  {
@@ -262,7 +262,7 @@ _gtk_plug_windowing_filter_func (GdkXEve
 		GtkWidget *widget = GTK_WIDGET (plug);
 
 		gdk_window_set_user_data (plug->socket_window, NULL);
-		g_object_unref (plug->socket_window);
+		g_object_unref_and_context (plug->socket_window);
 		plug->socket_window = NULL;
 
 		/* Emit a delete window, as if the user attempted
@@ -302,7 +302,7 @@ _gtk_plug_windowing_filter_func (GdkXEve
 		    break;
 		  }
 
-		g_object_ref (plug->socket_window);
+		g_object_ref_and_context (plug->socket_window);
 	      }
 	    else
 	      {
@@ -318,7 +318,7 @@ _gtk_plug_windowing_filter_func (GdkXEve
 	  }
 
       done:
-	g_object_unref (plug);
+	g_object_unref_and_context (plug);
 	
 	break;
       }
Index: gtk/gtkplug.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkplug.c,v
retrieving revision 1.78
diff -u -p -r1.78 gtkplug.c
--- gtk/gtkplug.c	14 May 2006 04:25:29 -0000	1.78
+++ gtk/gtkplug.c	19 Jul 2006 22:42:41 -0000
@@ -244,7 +244,7 @@ _gtk_plug_send_delete_event (GtkWidget *
 {
   GdkEvent *event = gdk_event_new (GDK_DELETE);
   
-  event->any.window = g_object_ref (widget->window);
+  event->any.window = g_object_ref_with_context (widget->window, &event->any.window);
   event->any.send_event = FALSE;
 
   gtk_widget_ref (widget);
@@ -281,8 +281,8 @@ _gtk_plug_remove_from_socket (GtkPlug   
   if (GTK_WIDGET_IN_REPARENT (widget))
     return;
 
-  g_object_ref (plug);
-  g_object_ref (socket_);
+  g_object_ref_and_context (plug);
+  g_object_ref_and_context (socket_);
 
   widget_was_visible = GTK_WIDGET_VISIBLE (plug);
   
@@ -315,12 +315,12 @@ _gtk_plug_remove_from_socket (GtkPlug   
   if (widget->window)
     _gtk_plug_send_delete_event (widget);
 
-  g_object_unref (plug);
+  g_object_unref_and_context (plug);
 
   if (widget_was_visible && GTK_WIDGET_VISIBLE (socket_))
     gtk_widget_queue_resize (GTK_WIDGET (socket_));
 
-  g_object_unref (socket_);
+  g_object_unref_and_context (socket_);
 }
 
 /**
Index: gtk/gtkradiobutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkradiobutton.c,v
retrieving revision 1.62
diff -u -p -r1.62 gtkradiobutton.c
--- gtk/gtkradiobutton.c	14 May 2006 04:25:29 -0000	1.62
+++ gtk/gtkradiobutton.c	19 Jul 2006 22:42:42 -0000
@@ -189,7 +189,7 @@ gtk_radio_button_set_group (GtkRadioButt
       radio_button->group = g_slist_remove (radio_button->group, radio_button);
       
       if (radio_button->group && !radio_button->group->next)
-	old_group_singleton = g_object_ref (radio_button->group->data);
+	old_group_singleton = g_object_ref_with_context (radio_button->group->data, &old_group_singleton);
 	  
       for (slist = radio_button->group; slist; slist = slist->next)
 	{
@@ -202,7 +202,7 @@ gtk_radio_button_set_group (GtkRadioButt
     }
   
   if (group && !group->next)
-    new_group_singleton = g_object_ref (group->data);
+    new_group_singleton = g_object_ref_with_context (group->data, &new_group_singleton);
   
   radio_button->group = g_slist_prepend (group, radio_button);
   
@@ -220,24 +220,24 @@ gtk_radio_button_set_group (GtkRadioButt
 	}
     }
 
-  g_object_ref (radio_button);
+  g_object_ref_and_context (radio_button);
   
   g_object_notify (G_OBJECT (radio_button), "group");
   g_signal_emit (radio_button, group_changed_signal, 0);
   if (old_group_singleton)
     {
       g_signal_emit (old_group_singleton, group_changed_signal, 0);
-      g_object_unref (old_group_singleton);
+      g_object_unref_and_context (old_group_singleton);
     }
   if (new_group_singleton)
     {
       g_signal_emit (new_group_singleton, group_changed_signal, 0);
-      g_object_unref (new_group_singleton);
+      g_object_unref_and_context (new_group_singleton);
     }
 
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
 
-  g_object_unref (radio_button);
+  g_object_unref_and_context (radio_button);
 }
 
 GtkWidget*
@@ -557,7 +557,7 @@ gtk_radio_button_clicked (GtkButton *but
   toggle_button = GTK_TOGGLE_BUTTON (button);
   toggled = FALSE;
 
-  g_object_ref (GTK_WIDGET (button));
+  g_object_ref_and_context (button);
 
   if (toggle_button->active)
     {
@@ -628,7 +628,7 @@ gtk_radio_button_clicked (GtkButton *but
 
   gtk_widget_queue_draw (GTK_WIDGET (button));
 
-  g_object_unref (button);
+  g_object_unref_and_context (button);
 }
 
 static void
Index: gtk/gtkradiomenuitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkradiomenuitem.c,v
retrieving revision 1.41
diff -u -p -r1.41 gtkradiomenuitem.c
--- gtk/gtkradiomenuitem.c	14 May 2006 04:25:29 -0000	1.41
+++ gtk/gtkradiomenuitem.c	19 Jul 2006 22:42:42 -0000
@@ -124,7 +124,7 @@ gtk_radio_menu_item_set_group (GtkRadioM
       radio_menu_item->group = g_slist_remove (radio_menu_item->group, radio_menu_item);
       
       if (radio_menu_item->group && !radio_menu_item->group->next)
-	old_group_singleton = g_object_ref (radio_menu_item->group->data);
+	old_group_singleton = g_object_ref_with_context (radio_menu_item->group->data, &old_group_singleton);
 	  
       for (slist = radio_menu_item->group; slist; slist = slist->next)
 	{
@@ -137,7 +137,7 @@ gtk_radio_menu_item_set_group (GtkRadioM
     }
   
   if (group && !group->next)
-    new_group_singleton = g_object_ref (group->data);
+    new_group_singleton = g_object_ref_with_context (group->data, &new_group_singleton);
   
   radio_menu_item->group = g_slist_prepend (group, radio_menu_item);
   
@@ -161,22 +161,22 @@ gtk_radio_menu_item_set_group (GtkRadioM
        */
     }
 
-  g_object_ref (radio_menu_item);
+  g_object_ref_and_context (radio_menu_item);
 
   g_object_notify (G_OBJECT (radio_menu_item), "group");
   g_signal_emit (radio_menu_item, group_changed_signal, 0);
   if (old_group_singleton)
     {
       g_signal_emit (old_group_singleton, group_changed_signal, 0);
-      g_object_unref (old_group_singleton);
+      g_object_unref_and_context (old_group_singleton);
     }
   if (new_group_singleton)
     {
       g_signal_emit (new_group_singleton, group_changed_signal, 0);
-      g_object_unref (new_group_singleton);
+      g_object_unref_and_context (new_group_singleton);
     }
 
-  g_object_unref (radio_menu_item);
+  g_object_unref_and_context (radio_menu_item);
 }
 
 GtkWidget*
Index: gtk/gtkrange.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrange.c,v
retrieving revision 1.128
diff -u -p -r1.128 gtkrange.c
--- gtk/gtkrange.c	18 Jul 2006 14:22:38 -0000	1.128
+++ gtk/gtkrange.c	19 Jul 2006 22:42:45 -0000
@@ -642,11 +642,11 @@ gtk_range_set_adjustment (GtkRange      
 	  g_signal_handlers_disconnect_by_func (range->adjustment,
 						gtk_range_adjustment_value_changed,
 						range);
-	  g_object_unref (range->adjustment);
+	  g_object_unref_and_context (range->adjustment);
 	}
 
       range->adjustment = adjustment;
-      g_object_ref_sink (adjustment);
+      g_object_ref_sink_with_context (adjustment, &range->adjustment);
       
       g_signal_connect (adjustment, "changed",
 			G_CALLBACK (gtk_range_adjustment_changed),
@@ -930,7 +930,7 @@ gtk_range_destroy (GtkObject *object)
       g_signal_handlers_disconnect_by_func (range->adjustment,
 					    gtk_range_adjustment_value_changed,
 					    range);
-      g_object_unref (range->adjustment);
+      g_object_unref_and_context (range->adjustment);
       range->adjustment = NULL;
     }
 
@@ -998,7 +998,7 @@ gtk_range_realize (GtkWidget *widget)
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.x = widget->allocation.x;
Index: gtk/gtkrc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrc.c,v
retrieving revision 1.181
diff -u -p -r1.181 gtkrc.c
--- gtk/gtkrc.c	7 Jul 2006 15:54:06 -0000	1.181
+++ gtk/gtkrc.c	19 Jul 2006 22:42:49 -0000
@@ -221,9 +221,6 @@ static guint       gtk_rc_parse_color_fu
                                                       GtkRcStyle      *style,
                                                       GdkColor        *color);
 
-static void        gtk_rc_clear_hash_node            (gpointer         key,
-                                                      gpointer         data,
-                                                      gpointer         user_data);
 static void        gtk_rc_clear_styles               (GtkRcContext    *context);
 static void        gtk_rc_add_initial_default_files  (void);
 
@@ -719,6 +716,62 @@ gtk_rc_context_get (GtkSettings *setting
   return settings->rc_context;
 }
 
+void
+_gtk_rc_context_destroy (GtkSettings *settings)
+{
+  GtkRcContext *context;
+  GSList *tmp_list;
+
+  g_return_if_fail (GTK_IS_SETTINGS (settings));
+
+  context = settings->rc_context;
+  if (!settings->rc_context)
+    return;
+
+  _gtk_settings_reset_rc_values (context->settings);
+  gtk_rc_clear_styles (context);
+
+  tmp_list = context->rc_files;
+  while (tmp_list)
+  {
+    GtkRcFile *rc_file = tmp_list->data;
+
+    if (rc_file->canonical_name != rc_file->name)
+      g_free (rc_file->canonical_name);
+    g_free (rc_file->directory);
+    g_free (rc_file->name);
+    g_free (rc_file);
+
+    tmp_list = tmp_list->next;
+  }
+  g_slist_free (context->rc_files);
+
+  if (context->default_style)
+    g_object_unref_with_context (context->default_style, context->default_style);
+
+  g_strfreev (context->pixmap_path);
+
+  g_free(context->theme_name);
+  g_free(context->key_theme_name);
+  g_free(context->font_name);
+
+  if (context->color_hash)
+    g_hash_table_unref (context->color_hash);
+
+  g_signal_handlers_disconnect_by_func (settings,
+      gtk_rc_settings_changed, context);
+  g_signal_handlers_disconnect_by_func (settings,
+      gtk_rc_font_name_changed, context);
+  g_signal_handlers_disconnect_by_func (settings,
+      gtk_rc_color_hash_changed, context);
+
+  rc_contexts = g_slist_remove (rc_contexts, context);
+
+  g_slice_free (GtkRcContext, context);
+
+  settings->rc_context = NULL;
+}
+
 static void
 gtk_rc_parse_named (GtkRcContext *context,
 		    const gchar  *name,
@@ -1457,14 +1510,6 @@ gtk_rc_style_copy_icons_and_colors (GtkR
 }
 
 static void
-gtk_rc_clear_hash_node (gpointer key, 
-			gpointer data, 
-			gpointer user_data)
-{
-  gtk_rc_style_unref (data);
-}
-
-static void
 gtk_rc_free_rc_sets (GSList *slist)
 {
   while (slist)
@@ -1485,7 +1530,6 @@ gtk_rc_clear_styles (GtkRcContext *conte
 
   if (context->rc_style_ht)
     {
-      g_hash_table_foreach (context->rc_style_ht, gtk_rc_clear_hash_node, NULL);
       g_hash_table_destroy (context->rc_style_ht);
       context->rc_style_ht = NULL;
     }
@@ -1580,7 +1624,7 @@ gtk_rc_reset_styles (GtkSettings *settin
   
   if (context->default_style)
     {
-      g_object_unref (context->default_style);
+      g_object_unref_with_context (context->default_style, context->default_style);
       context->default_style = NULL;
       reset = TRUE;
     }
@@ -1855,7 +1899,7 @@ gtk_rc_get_style (GtkWidget *widget)
   GSList *rc_styles = NULL;
   GtkRcContext *context;
 
-  static guint rc_style_key_id = 0;
+  static GQuark rc_style_key_id;
 
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
 
@@ -2283,9 +2327,7 @@ gtk_rc_style_to_style (GtkRcContext *con
   style = GTK_RC_STYLE_GET_CLASS (rc_style)->create_style (rc_style);
   _gtk_style_init_for_settings (style, context->settings);
 
-  style->rc_style = rc_style;
-
-  gtk_rc_style_ref (rc_style);
+  style->rc_style = g_object_ref_with_context (rc_style, &style->rc_style);
   
   GTK_STYLE_GET_CLASS (style)->init_from_rc (style, rc_style);  
 
@@ -2366,7 +2408,7 @@ gtk_rc_init_style (GtkRcContext *context
 	  }
 
       style = gtk_rc_style_to_style (context, proto_style);
-      gtk_rc_style_unref (proto_style);
+      g_object_unref (proto_style);
 
       g_hash_table_insert (realized_style_ht, rc_styles, style);
     }
@@ -2749,7 +2791,7 @@ gtk_rc_parse_style (GtkRcContext *contex
   
   rc_style = gtk_rc_style_find (context, scanner->value.v_string);
   if (rc_style)
-    orig_style = g_object_ref (rc_style);
+    orig_style = g_object_ref_with_context (rc_style, &orig_style);
   else
     orig_style = NULL;
 
@@ -2964,8 +3006,10 @@ gtk_rc_parse_style (GtkRcContext *contex
   if (rc_style != orig_style)
     {
       if (!context->rc_style_ht)
-	context->rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
-						 (GEqualFunc) gtk_rc_style_equal);
+	context->rc_style_ht = g_hash_table_new_full (
+	    (GHashFunc) gtk_rc_style_hash,
+	    (GEqualFunc) gtk_rc_style_equal,
+	    NULL, g_object_unref);
       
       g_hash_table_replace (context->rc_style_ht, rc_style->name, rc_style);
 
@@ -2977,16 +3021,16 @@ gtk_rc_parse_style (GtkRcContext *contex
     }
 
   if (orig_style)
-    g_object_unref (orig_style);
+    g_object_unref_and_context (orig_style);
   
   return G_TOKEN_NONE;
 
  err:
   if (rc_style != orig_style)
-    gtk_rc_style_unref (rc_style);
+    g_object_unref_with_context (rc_style, rc_style);
 
   if (orig_style)
-    g_object_unref (orig_style);
+    g_object_unref_and_context (orig_style);
   
   return token;
 }
Index: gtk/gtkrecentchoosermenu.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrecentchoosermenu.c,v
retrieving revision 1.9
diff -u -p -r1.9 gtkrecentchoosermenu.c
--- gtk/gtkrecentchoosermenu.c	6 Jul 2006 05:14:02 -0000	1.9
+++ gtk/gtkrecentchoosermenu.c	19 Jul 2006 22:42:51 -0000
@@ -268,7 +268,7 @@ gtk_recent_chooser_menu_finalize (GObjec
   if (priv->current_filter)
     g_object_unref (priv->current_filter);
   
-  G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->finalize;
+  G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->finalize (object);
 }
 
 static GObject *
Index: gtk/gtkselection.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkselection.c,v
retrieving revision 1.110
diff -u -p -r1.110 gtkselection.c
--- gtk/gtkselection.c	6 Jul 2006 05:14:02 -0000	1.110
+++ gtk/gtkselection.c	19 Jul 2006 22:42:53 -0000
@@ -712,7 +712,7 @@ gtk_selection_owner_set_for_display (Gdk
 	{
 	  GdkEvent *event = gdk_event_new (GDK_SELECTION_CLEAR);
 	  
-	  event->selection.window = g_object_ref (old_owner->window);
+	  event->selection.window = g_object_ref_with_context (old_owner->window, &event->selection.window);
 	  event->selection.selection = selection;
 	  event->selection.time = time;
 	  
@@ -1536,7 +1536,7 @@ gtk_selection_data_get_pixbuf (GtkSelect
       if (result)
 	g_object_ref (result);
       
-      g_object_unref (loader);
+      g_object_unref_with_context (loader, loader);
     }
 
   return result;
@@ -2095,7 +2095,7 @@ _gtk_selection_request (GtkWidget *widge
   
   info = g_new (GtkIncrInfo, 1);
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   
   info->selection = event->selection;
   info->num_incrs = 0;
@@ -2309,7 +2309,7 @@ _gtk_selection_request (GtkWidget *widge
       g_free (info);
     }
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
   
   return TRUE;
 }
Index: gtk/gtksettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.c,v
retrieving revision 1.98
diff -u -p -r1.98 gtksettings.c
--- gtk/gtksettings.c	7 Jul 2006 15:54:06 -0000	1.98
+++ gtk/gtksettings.c	19 Jul 2006 22:42:55 -0000
@@ -97,6 +97,7 @@ enum {
 
 
 /* --- prototypes --- */
+static void	gtk_settings_dispose		 (GObject		*object);
 static void	gtk_settings_finalize		 (GObject		*object);
 static void	gtk_settings_get_property	 (GObject		*object,
 						  guint			 property_id,
@@ -179,6 +180,7 @@ gtk_settings_class_init (GtkSettingsClas
   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
   guint result;
   
+  gobject_class->dispose  = gtk_settings_dispose;
   gobject_class->finalize = gtk_settings_finalize;
   gobject_class->get_property = gtk_settings_get_property;
   gobject_class->set_property = gtk_settings_set_property;
@@ -513,6 +515,16 @@ gtk_settings_class_init (GtkSettingsClas
 }
 
 static void
+gtk_settings_dispose (GObject *object)
+{
+  GtkSettings *settings = GTK_SETTINGS (object);
+
+  _gtk_rc_context_destroy (settings);
+
+  G_OBJECT_CLASS (gtk_settings_parent_class)->dispose (object);
+}
+
+static void
 gtk_settings_finalize (GObject *object)
 {
   GtkSettings *settings = GTK_SETTINGS (object);
@@ -526,9 +538,17 @@ gtk_settings_finalize (GObject *object)
 
   g_datalist_clear (&settings->queued_settings);
 
+  _gtk_rc_context_destroy (settings);
+
   G_OBJECT_CLASS (gtk_settings_parent_class)->finalize (object);
 }
 
+static void
+settings_unref (gpointer ptr)
+{
+  g_object_unref_with_context (ptr, ptr);
+}
+
 /**
  * gtk_settings_get_for_screen:
  * @screen : a #GdkScreen.
@@ -551,7 +571,8 @@ gtk_settings_get_for_screen (GdkScreen *
     {
       settings = g_object_new (GTK_TYPE_SETTINGS, NULL);
       settings->screen = screen;
-      g_object_set_data (G_OBJECT (screen), I_("gtk-settings"), settings);
+      g_object_set_data_full (G_OBJECT (screen),
+	  I_("gtk-settings"), settings, settings_unref);
 
       gtk_rc_reparse_all_for_settings (settings, TRUE);
       settings_update_double_click (settings);
Index: gtk/gtksizegroup.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksizegroup.c,v
retrieving revision 1.26
diff -u -p -r1.26 gtksizegroup.c
--- gtk/gtksizegroup.c	16 Jun 2006 17:22:30 -0000	1.26
+++ gtk/gtksizegroup.c	19 Jul 2006 22:42:56 -0000
@@ -496,7 +496,7 @@ gtk_size_group_add_widget (GtkSizeGroup 
 			G_CALLBACK (gtk_size_group_widget_destroyed),
 			size_group);
 
-      g_object_ref (size_group);
+      g_object_ref_with_context (size_group, widget);
     }
   
   queue_resize_on_group (size_group);
@@ -531,7 +531,7 @@ gtk_size_group_remove_widget (GtkSizeGro
   queue_resize_on_group (size_group);
   gtk_widget_queue_resize (widget);
 
-  g_object_unref (size_group);
+  g_object_unref_with_context (size_group, widget);
 }
 
 /**
@@ -595,6 +595,17 @@ compute_base_dimension (GtkWidget       
   return get_base_dimension (widget, mode);
 }
 
+static void
+widget_ref_with_context (gpointer ptr, gpointer ctx)
+{
+  g_object_ref_with_context (ptr, ctx);
+}
+static void
+widget_unref_with_context (gpointer ptr, gpointer ctx)
+{
+  g_object_unref_with_context (ptr, ctx);
+}
+
 static gint
 compute_dimension (GtkWidget        *widget,
 		   GtkSizeGroupMode  mode)
@@ -609,7 +620,7 @@ compute_dimension (GtkWidget        *wid
   g_slist_foreach (widgets, (GFunc)mark_unvisited, NULL);
   g_slist_foreach (groups, (GFunc)mark_unvisited, NULL);
   
-  g_slist_foreach (widgets, (GFunc)g_object_ref, NULL);
+  g_slist_foreach (widgets, widget_ref_with_context, compute_dimension);
   
   if (!groups)
     {
@@ -662,7 +673,7 @@ compute_dimension (GtkWidget        *wid
 	}
     }
 
-  g_slist_foreach (widgets, (GFunc)g_object_unref, NULL);
+  g_slist_foreach (widgets, widget_unref_with_context, compute_dimension);
 
   g_slist_free (widgets);
   g_slist_free (groups);
Index: gtk/gtksocket-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksocket-x11.c,v
retrieving revision 1.5
diff -u -p -r1.5 gtksocket-x11.c
--- gtk/gtksocket-x11.c	30 Sep 2005 14:57:02 -0000	1.5
+++ gtk/gtksocket-x11.c	19 Jul 2006 22:42:56 -0000
@@ -504,11 +504,11 @@ _gtk_socket_windowing_filter_func (GdkXE
 	    gdk_window_destroy_notify (socket->plug_window);
 	    _gtk_socket_end_embedding (socket);
 
-	    g_object_ref (widget);
+	    g_object_ref_and_context (widget);
 	    g_signal_emit_by_name (widget, "plug_removed", &result);
 	    if (!result)
 	      gtk_widget_destroy (widget);
-	    g_object_unref (widget);
+	    g_object_unref_and_context (widget);
 	    
 	    return_val = GDK_FILTER_REMOVE;
 	  }
Index: gtk/gtksocket.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksocket.c,v
retrieving revision 1.72
diff -u -p -r1.72 gtksocket.c
--- gtk/gtksocket.c	14 May 2006 04:25:29 -0000	1.72
+++ gtk/gtksocket.c	19 Jul 2006 22:42:57 -0000
@@ -105,7 +105,7 @@ gtk_socket_finalize (GObject *object)
 {
   GtkSocket *socket = GTK_SOCKET (object);
   
-  g_object_unref (socket->accel_group);
+  g_object_unref_and_context (socket->accel_group);
   socket->accel_group = NULL;
 
   G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
@@ -345,7 +345,7 @@ _gtk_socket_end_embedding (GtkSocket *so
   if (toplevel && GTK_IS_WINDOW (toplevel))
     _gtk_socket_windowing_end_embedding_toplevel (socket);
 
-  g_object_unref (socket->plug_window);
+  g_object_unref_and_context (socket->plug_window);
   socket->plug_window = NULL;
   socket->current_width = 0;
   socket->current_height = 0;
@@ -797,7 +797,7 @@ _gtk_socket_add_window (GtkSocket       
 
   if (socket->plug_window)
     {
-      g_object_ref (socket->plug_window);
+      g_object_ref_and_context (socket->plug_window);
       gdk_window_get_user_data (socket->plug_window, &user_data);
     }
 
@@ -837,7 +837,7 @@ _gtk_socket_add_window (GtkSocket       
 
       if (gdk_error_trap_pop ())
 	{
-	  g_object_unref (socket->plug_window);
+	  g_object_unref_and_context (socket->plug_window);
 	  socket->plug_window = NULL;
 	  return;
 	}
Index: gtk/gtkspinbutton.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkspinbutton.c,v
retrieving revision 1.127
diff -u -p -r1.127 gtkspinbutton.c
--- gtk/gtkspinbutton.c	14 May 2006 04:25:29 -0000	1.127
+++ gtk/gtkspinbutton.c	19 Jul 2006 22:42:59 -0000
@@ -1671,12 +1671,12 @@ gtk_spin_button_set_adjustment (GtkSpinB
 	  g_signal_handlers_disconnect_by_func (spin_button->adjustment,
 						adjustment_changed_cb,
 						spin_button);
-	  g_object_unref (spin_button->adjustment);
+	  g_object_unref_and_context (spin_button->adjustment);
         }
       spin_button->adjustment = adjustment;
       if (adjustment)
         {
-	  g_object_ref_sink (adjustment);
+	  g_object_ref_sink_with_context (adjustment, &spin_button->adjustment);
 	  g_signal_connect (adjustment, "value_changed",
 			    G_CALLBACK (gtk_spin_button_value_changed),
 			    spin_button);
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.194
diff -u -p -r1.194 gtkstyle.c
--- gtk/gtkstyle.c	6 Jul 2006 05:14:02 -0000	1.194
+++ gtk/gtkstyle.c	19 Jul 2006 22:43:06 -0000
@@ -617,7 +617,7 @@ gtk_style_finalize (GObject *object)
     pango_font_description_free (style->private_font_desc);
   
   if (style->rc_style)
-    gtk_rc_style_unref (style->rc_style);
+    g_object_unref_and_context (style->rc_style);
   
   G_OBJECT_CLASS (gtk_style_parent_class)->finalize (object);
 }
@@ -752,7 +752,7 @@ gtk_style_attach (GtkStyle  *style,
 
   /* A style gets a refcount from being attached */
   if (new_style->attach_count == 0)
-    g_object_ref (new_style);
+    g_object_ref_with_context (new_style, gtk_style_attach);
 
   /* Another refcount belongs to the parent */
   if (style != new_style) 
@@ -785,7 +785,7 @@ gtk_style_detach (GtkStyle *style)
     {
       g_signal_emit (style, unrealize_signal, 0);
       
-      g_object_unref (style->colormap);
+      g_object_unref_and_context (style->colormap);
       style->colormap = NULL;
 
       if (style->private_font_desc)
@@ -800,7 +800,7 @@ gtk_style_detach (GtkStyle *style)
 	  style->private_font_desc = NULL;
 	}
 
-      g_object_unref (style);
+      g_object_unref_with_context (style, gtk_style_attach);
     }
 }
 
@@ -833,7 +833,7 @@ static void
 gtk_style_realize (GtkStyle    *style,
                    GdkColormap *colormap)
 {
-  style->colormap = g_object_ref (colormap);
+  style->colormap = g_object_ref_with_context (colormap, &style->colormap);
   style->depth = gdk_colormap_get_visual (colormap)->depth;
 
   g_signal_emit (style, realize_signal, 0);
@@ -1614,10 +1614,10 @@ gtk_style_real_copy (GtkStyle *style,
   style->ythickness = src->ythickness;
 
   if (style->rc_style)
-    gtk_rc_style_unref (style->rc_style);
+    g_object_unref_and_context (style->rc_style);
   style->rc_style = src->rc_style;
   if (src->rc_style)
-    gtk_rc_style_ref (src->rc_style);
+    g_object_ref_and_context (src->rc_style);
 
   /* don't copy, just clear cache */
   clear_property_cache (style);
@@ -4895,7 +4895,7 @@ static ByteRange*
 range_new (guint start,
            guint end)
 {
-  ByteRange *br = g_new (ByteRange, 1);
+  ByteRange *br = g_slice_new (ByteRange);
 
   br->start = start;
   br->end = end;
@@ -4987,7 +4987,7 @@ get_insensitive_layout (GdkDrawable *dra
       
       pango_attr_list_change (attrs, attr);
 
-      g_free (br);
+      g_slice_free (ByteRange, br);
       
       tmp_list = g_slist_next (tmp_list);
     }
@@ -5020,7 +5020,7 @@ get_insensitive_layout (GdkDrawable *dra
       
       pango_attr_list_change (attrs, attr);
 
-      g_free (br);
+      g_slice_free (ByteRange, br);
       
       tmp_list = g_slist_next (tmp_list);
     }
@@ -6552,7 +6552,7 @@ style_unrealize_cursor_gcs (GtkStyle *st
       if (cursor_info->secondary_gc)
 	gtk_gc_release (cursor_info->secondary_gc);
       
-      g_free (cursor_info);
+      g_slice_free (CursorInfo, cursor_info);
       g_object_set_data (G_OBJECT (style), I_("gtk-style-cursor-info"), NULL);
     }
 }
@@ -6590,7 +6590,7 @@ get_insertion_cursor_gc (GtkWidget *widg
   cursor_info = g_object_get_data (G_OBJECT (widget->style), "gtk-style-cursor-info");
   if (!cursor_info)
     {
-      cursor_info = g_new (CursorInfo, 1);
+      cursor_info = g_slice_new (CursorInfo);
       g_object_set_data (G_OBJECT (widget->style), I_("gtk-style-cursor-info"), cursor_info);
       cursor_info->primary_gc = NULL;
       cursor_info->secondary_gc = NULL;
Index: gtk/gtkstyle.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.h,v
retrieving revision 1.49
diff -u -p -r1.49 gtkstyle.h
--- gtk/gtkstyle.h	23 Nov 2005 10:33:58 -0000	1.49
+++ gtk/gtkstyle.h	19 Jul 2006 22:43:07 -0000
@@ -427,7 +427,7 @@ GType     gtk_style_get_type            
 GtkStyle* gtk_style_new			     (void);
 GtkStyle* gtk_style_copy		     (GtkStyle	   *style);
 GtkStyle* gtk_style_attach		     (GtkStyle	   *style,
-					      GdkWindow	   *window);
+					      GdkWindow	   *window) G_GNUC_WARN_UNUSED_RESULT;
 void	  gtk_style_detach		     (GtkStyle	   *style);
 
 #ifndef GTK_DISABLE_DEPRECATED
Index: gtk/gtktextbtree.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextbtree.c,v
retrieving revision 1.89
diff -u -p -r1.89 gtktextbtree.c
--- gtk/gtktextbtree.c	14 May 2006 03:46:14 -0000	1.89
+++ gtk/gtktextbtree.c	19 Jul 2006 22:43:13 -0000
@@ -426,7 +426,7 @@ _gtk_text_btree_new (GtkTextTagTable *ta
   tree->end_iter_segment_byte_index = 0;
   tree->end_iter_segment_char_offset = 0;
   
-  g_object_ref (tree->table);
+  g_object_ref_and_context (tree->table);
 
   tree->tag_changed_handler = g_signal_connect (tree->table,
 						"tag_changed",
@@ -472,8 +472,8 @@ _gtk_text_btree_new (GtkTextTagTable *ta
 
     seg->body.mark.not_deleteable = TRUE;
 
-    g_object_ref (tree->insert_mark);
-    g_object_ref (tree->selection_bound_mark);
+    g_object_ref_and_context (tree->insert_mark);
+    g_object_ref_and_context (tree->selection_bound_mark);
   }
 
   tree->refcount = 1;
@@ -503,7 +503,7 @@ _gtk_text_btree_unref (GtkTextBTree *tre
       g_signal_handler_disconnect (tree->table,
                                    tree->tag_changed_handler);
 
-      g_object_unref (tree->table);
+      g_object_unref_and_context (tree->table);
       tree->table = NULL;
       
       gtk_text_btree_node_destroy (tree, tree->root_node);
@@ -518,9 +518,9 @@ _gtk_text_btree_unref (GtkTextBTree *tre
 	  tree->child_anchor_table = NULL;
 	}
 
-      g_object_unref (tree->insert_mark);
+      g_object_unref_and_context (tree->insert_mark);
       tree->insert_mark = NULL;
-      g_object_unref (tree->selection_bound_mark);
+      g_object_unref_and_context (tree->selection_bound_mark);
       tree->selection_bound_mark = NULL;
 
       g_free (tree);
@@ -2890,7 +2890,7 @@ _gtk_text_btree_release_mark_segment (Gt
   /* Remove the ref on the mark, which frees segment as a side effect
    * if this is the last reference.
    */
-  g_object_unref (segment->body.mark.obj);
+  g_object_unref_with_context (segment->body.mark.obj, segment->body.mark.obj);
 }
 
 void
@@ -5952,7 +5952,7 @@ gtk_text_btree_get_tag_info (GtkTextBTre
       info = g_slice_new (GtkTextTagInfo);
 
       info->tag = tag;
-      g_object_ref (tag);
+      g_object_ref_and_context (info->tag);
       info->tag_root = NULL;
       info->toggle_count = 0;
 
@@ -6000,7 +6000,7 @@ gtk_text_btree_remove_tag_info (GtkTextB
           list->next = NULL;
           g_slist_free (list);
 
-          g_object_unref (info->tag);
+          g_object_unref_and_context (info->tag);
 
           g_slice_free (GtkTextTagInfo, info);
           return;
Index: gtk/gtktextbuffer.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextbuffer.c,v
retrieving revision 1.116
diff -u -p -r1.116 gtktextbuffer.c
--- gtk/gtktextbuffer.c	14 May 2006 04:25:30 -0000	1.116
+++ gtk/gtktextbuffer.c	19 Jul 2006 22:43:17 -0000
@@ -434,7 +434,7 @@ set_table (GtkTextBuffer *buffer, GtkTex
   if (table)
     {
       buffer->tag_table = table;
-      g_object_ref (buffer->tag_table);
+      g_object_ref_and_context (buffer->tag_table);
       _gtk_text_tag_table_add_buffer (table, buffer);
     }
 }
@@ -445,6 +445,8 @@ get_table (GtkTextBuffer *buffer)
   if (buffer->tag_table == NULL)
     {
       buffer->tag_table = gtk_text_tag_table_new ();
+      g_object_ref_set_context (buffer->tag_table,
+	  buffer->tag_table, &buffer->tag_table);
       _gtk_text_tag_table_add_buffer (buffer->tag_table, buffer);
     }
 
@@ -574,7 +576,7 @@ gtk_text_buffer_finalize (GObject *objec
   if (buffer->tag_table)
     {
       _gtk_text_tag_table_remove_buffer (buffer->tag_table, buffer);
-      g_object_unref (buffer->tag_table);
+      g_object_unref_and_context (buffer->tag_table);
       buffer->tag_table = NULL;
     }
 
@@ -881,7 +883,7 @@ save_range (GtkTextIter *range_start,
   r = g_new (Range, 1);
 
   r->buffer = gtk_text_iter_get_buffer (range_start);
-  g_object_ref (r->buffer);
+  g_object_ref_and_context (r->buffer);
   
   r->start_mark = 
     gtk_text_buffer_create_mark (gtk_text_iter_get_buffer (range_start),
@@ -937,7 +939,7 @@ restore_range (Range *r)
   if (gtk_text_iter_compare (r->range_end, r->whole_end) > 0)
     *r->range_end = *r->whole_end;
   
-  g_object_unref (r->buffer);
+  g_object_unref_and_context (r->buffer);
   g_free (r); 
 }
 
@@ -1809,7 +1811,7 @@ gtk_text_buffer_mark_set (GtkTextBuffer 
    * default behavior.
    */
 
-  g_object_ref (mark);
+  g_object_ref_and_context (mark);
 
   g_signal_emit (buffer,
                  signals[MARK_SET],
@@ -1817,7 +1819,7 @@ gtk_text_buffer_mark_set (GtkTextBuffer 
                  location,
                  mark);
 
-  g_object_unref (mark);
+  g_object_unref_and_context (mark);
 }
 
 /**
@@ -1974,7 +1976,7 @@ gtk_text_buffer_delete_mark (GtkTextBuff
   g_return_if_fail (!gtk_text_mark_get_deleted (mark));
   g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
 
-  g_object_ref (mark);
+  g_object_ref_and_context (mark);
 
   _gtk_text_btree_remove_mark (get_btree (buffer), mark);
 
@@ -1986,7 +1988,7 @@ gtk_text_buffer_delete_mark (GtkTextBuff
                  0,
                  mark);
 
-  g_object_unref (mark);
+  g_object_unref_and_context (mark);
 }
 
 /**
@@ -2495,6 +2497,17 @@ pointer_cmp (gconstpointer a,
     return 0;
 }
 
+static void
+tag_ref_with_context (gpointer ptr, gpointer ctx)
+{
+  g_object_ref_with_context (ptr, ctx);
+}
+static void
+tag_unref_with_context (gpointer ptr, gpointer ctx)
+{
+  g_object_ref_with_context (ptr, ctx);
+}
+
 /**
  * gtk_text_buffer_remove_all_tags:
  * @buffer: a #GtkTextBuffer
@@ -2590,7 +2603,7 @@ gtk_text_buffer_remove_all_tags (GtkText
         }
     }
 
-  g_slist_foreach (tags, (GFunc) g_object_ref, NULL);
+  g_slist_foreach (tags, tag_ref_with_context, gtk_text_buffer_remove_all_tags);
   
   tmp_list = tags;
   while (tmp_list != NULL)
@@ -2602,7 +2615,7 @@ gtk_text_buffer_remove_all_tags (GtkText
       tmp_list = tmp_list->next;
     }
 
-  g_slist_foreach (tags, (GFunc) g_object_unref, NULL);
+  g_slist_foreach (tags, tag_unref_with_context, gtk_text_buffer_remove_all_tags);
   
   g_slist_free (tags);
 }
@@ -2956,6 +2969,11 @@ clipboard_get_selection_cb (GtkClipboard
     }
 }
 
+static void
+buffer_unref_with_context (gpointer buffer, gpointer context)
+{
+  g_object_unref_with_context (buffer, context);
+}
 static GtkTextBuffer *
 create_clipboard_contents_buffer (GtkTextBuffer *buffer)
 {
@@ -2972,8 +2990,8 @@ create_clipboard_contents_buffer (GtkTex
    *  exists, because it's needed for serializing the contents buffer.
    *  See http://bugzilla.gnome.org/show_bug.cgi?id=339195
    */
-  g_object_ref (buffer);
-  g_object_weak_ref (G_OBJECT (contents), (GWeakNotify) g_object_unref, buffer);
+  g_object_ref_with_context (buffer, contents);
+  g_object_weak_ref (G_OBJECT (contents), (GWeakNotify) buffer_unref_with_context, buffer);
 
   return contents;
 }
@@ -3288,7 +3306,7 @@ paste_from_buffer (ClipboardRequest    *
   GtkTextBuffer *buffer = request_data->buffer;
   
   /* We're about to emit a bunch of signals, so be safe */
-  g_object_ref (src_buffer);
+  g_object_ref_and_context (src_buffer);
   
   pre_paste_prep (request_data, &insert_point);
   
@@ -3312,7 +3330,7 @@ paste_from_buffer (ClipboardRequest    *
   if (request_data->interactive) 
     gtk_text_buffer_end_user_action (buffer);
 
-  g_object_unref (src_buffer);
+  g_object_unref_and_context (src_buffer);
 
   free_clipboard_request (request_data);
 }
@@ -3550,7 +3568,7 @@ gtk_text_buffer_paste_clipboard (GtkText
                                  "gtk_paste_point_override",
                                  override_location, FALSE);
 
-  data->buffer = g_object_ref (buffer);
+  data->buffer = g_object_ref_with_context (buffer, &data->buffer);
   data->interactive = TRUE;
   data->default_editable = default_editable;
 
Index: gtk/gtktextchild.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextchild.c,v
retrieving revision 1.32
diff -u -p -r1.32 gtktextchild.c
--- gtk/gtktextchild.c	14 May 2006 04:25:30 -0000	1.32
+++ gtk/gtktextchild.c	19 Jul 2006 22:43:18 -0000
@@ -86,7 +86,7 @@ pixbuf_segment_delete_func (GtkTextLineS
                             gboolean            tree_gone)
 {
   if (seg->body.pixbuf.pixbuf)
-    g_object_unref (seg->body.pixbuf.pixbuf);
+    g_object_unref_and_context (seg->body.pixbuf.pixbuf);
 
   g_free (seg);
 
@@ -139,8 +139,7 @@ _gtk_pixbuf_segment_new (GdkPixbuf *pixb
   seg->char_count = 1;
 
   seg->body.pixbuf.pixbuf = pixbuf;
-
-  g_object_ref (pixbuf);
+  g_object_ref_and_context (seg->body.pixbuf.pixbuf);
 
   return seg;
 }
Index: gtk/gtktextdisplay.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextdisplay.c,v
retrieving revision 1.56
diff -u -p -r1.56 gtktextdisplay.c
--- gtk/gtktextdisplay.c	6 Jul 2006 05:14:03 -0000	1.56
+++ gtk/gtktextdisplay.c	19 Jul 2006 22:43:19 -0000
@@ -646,14 +646,12 @@ render_para (GtkTextRenderer    *text_re
 }
 
 static void
-on_renderer_display_closed (GdkDisplay       *display,
-                            gboolean          is_error,
+on_renderer_screen_closed (GdkScreen       *screen,
 			    GtkTextRenderer  *text_renderer)
 {
-  g_signal_handlers_disconnect_by_func (text_renderer->screen,
-					(gpointer)on_renderer_display_closed,
-					text_renderer);
-  g_object_set_data (G_OBJECT (text_renderer->screen), I_("gtk-text-renderer"), NULL);
+  g_object_set_data (G_OBJECT (screen), I_("gtk-text-renderer"), NULL);
+
+  g_object_unref_with_context (text_renderer, text_renderer);
 }
 
 static GtkTextRenderer *
@@ -669,11 +667,10 @@ get_text_renderer (GdkScreen *screen)
       text_renderer = g_object_new (GTK_TYPE_TEXT_RENDERER, "screen", screen, NULL);
       text_renderer->screen = screen;
       
-      g_object_set_data_full (G_OBJECT (screen), I_("gtk-text-renderer"), text_renderer,
-			      (GDestroyNotify)g_object_unref);
+      g_object_set_data (G_OBJECT (screen), I_("gtk-text-renderer"), text_renderer);
 
-      g_signal_connect_object (gdk_screen_get_display (screen), "closed",
-                               G_CALLBACK (on_renderer_display_closed),
+      g_signal_connect_object (screen, "closed",
+                               G_CALLBACK (on_renderer_screen_closed),
                                text_renderer, 0);
     }
 
Index: gtk/gtktextlayout.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextlayout.c,v
retrieving revision 1.117
diff -u -p -r1.117 gtktextlayout.c
--- gtk/gtktextlayout.c	14 May 2006 04:25:30 -0000	1.117
+++ gtk/gtktextlayout.c	19 Jul 2006 22:43:22 -0000
@@ -250,12 +250,12 @@ gtk_text_layout_finalize (GObject *objec
 
   if (layout->ltr_context)
     {
-      g_object_unref (layout->ltr_context);
+      g_object_unref_and_context (layout->ltr_context);
       layout->ltr_context = NULL;
     }
   if (layout->rtl_context)
     {
-      g_object_unref (layout->rtl_context);
+      g_object_unref_and_context (layout->rtl_context);
       layout->rtl_context = NULL;
     }
   
@@ -309,15 +309,14 @@ gtk_text_layout_set_buffer (GtkTextLayou
                                             G_CALLBACK (gtk_text_layout_buffer_delete_range), 
                                             layout);
 
-      g_object_unref (layout->buffer);
+      g_object_unref_and_context (layout->buffer);
       layout->buffer = NULL;
     }
 
   if (buffer)
     {
       layout->buffer = buffer;
-
-      g_object_ref (buffer);
+      g_object_ref_and_context (layout->buffer);
 
       _gtk_text_btree_add_view (_gtk_text_buffer_get_btree (buffer), layout);
 
@@ -369,17 +368,23 @@ gtk_text_layout_set_contexts (GtkTextLay
 {
   g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
 
-  if (layout->ltr_context)
-    g_object_unref (ltr_context);
+  if (layout->ltr_context != ltr_context)
+    {
+      if (layout->ltr_context)
+	g_object_unref_and_context (layout->ltr_context);
 
-  layout->ltr_context = ltr_context;
-  g_object_ref (ltr_context);
+      layout->ltr_context = ltr_context;
+      g_object_ref_and_context (layout->ltr_context);
+    }
 
-  if (layout->rtl_context)
-    g_object_unref (rtl_context);
+  if (layout->rtl_context != rtl_context)
+    {
+      if (layout->rtl_context)
+	g_object_unref_and_context (layout->rtl_context);
 
-  layout->rtl_context = rtl_context;
-  g_object_ref (rtl_context);
+      layout->rtl_context = rtl_context;
+      g_object_ref_and_context (layout->rtl_context);
+    }
 
   DV (g_print ("invalidating all due to new pango contexts (%s)\n", G_STRLOC));
   gtk_text_layout_invalidate_all (layout);
@@ -1307,9 +1312,9 @@ gtk_text_attr_appearance_destroy (PangoA
   GtkTextAttrAppearance *appearance_attr = (GtkTextAttrAppearance *)attr;
 
   if (appearance_attr->appearance.bg_stipple)
-    g_object_unref (appearance_attr->appearance.bg_stipple);
+    g_object_unref_and_context (appearance_attr->appearance.bg_stipple);
   if (appearance_attr->appearance.fg_stipple)
-    g_object_unref (appearance_attr->appearance.fg_stipple);
+    g_object_unref_and_context (appearance_attr->appearance.fg_stipple);
 
   g_slice_free (GtkTextAttrAppearance, appearance_attr);
 }
@@ -1362,10 +1367,10 @@ gtk_text_attr_appearance_new (const GtkT
 
   result->appearance = *appearance;
 
-  if (appearance->bg_stipple)
-    g_object_ref (appearance->bg_stipple);
-  if (appearance->fg_stipple)
-    g_object_ref (appearance->fg_stipple);
+  if (result->appearance.bg_stipple)
+    g_object_ref_and_context (result->appearance.bg_stipple);
+  if (result->appearance.fg_stipple)
+    g_object_ref_and_context (result->appearance.fg_stipple);
 
   return (PangoAttribute *)result;
 }
Index: gtk/gtktexttagtable.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktexttagtable.c,v
retrieving revision 1.35
diff -u -p -r1.35 gtktexttagtable.c
--- gtk/gtktexttagtable.c	14 May 2006 04:25:30 -0000	1.35
+++ gtk/gtktexttagtable.c	19 Jul 2006 22:43:23 -0000
@@ -224,7 +224,7 @@ gtk_text_tag_table_add (GtkTextTagTable 
       return;
     }
   
-  g_object_ref (tag);
+  g_object_ref_with_context (tag, &tag->table);
 
   if (tag->name)
     g_hash_table_insert (table->hash, tag->name, tag);
@@ -313,7 +313,7 @@ gtk_text_tag_table_remove (GtkTextTagTab
 
   g_signal_emit (table, signals[TAG_REMOVED], 0, tag);
 
-  g_object_unref (tag);
+  g_object_unref_with_context (tag, &tag->table);
 }
 
 struct ForeachData
Index: gtk/gtktextview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktextview.c,v
retrieving revision 1.319
diff -u -p -r1.319 gtktextview.c
--- gtk/gtktextview.c	6 Jul 2006 05:14:03 -0000	1.319
+++ gtk/gtktextview.c	19 Jul 2006 22:43:31 -0000
@@ -1163,7 +1163,7 @@ gtk_text_view_set_buffer (GtkTextView   
       g_signal_handlers_disconnect_by_func (text_view->buffer,
                                             gtk_text_view_target_list_notify,
                                             text_view);
-      g_object_unref (text_view->buffer);
+      g_object_unref_and_context (text_view->buffer);
       text_view->dnd_mark = NULL;
 
       if (GTK_WIDGET_REALIZED (text_view))
@@ -1180,7 +1180,7 @@ gtk_text_view_set_buffer (GtkTextView   
     {
       GtkTextIter start;
 
-      g_object_ref (buffer);
+      g_object_ref_and_context (text_view->buffer);
 
       if (text_view->layout)
         gtk_text_layout_set_buffer (text_view->layout, buffer);
@@ -1619,7 +1619,7 @@ free_pending_scroll (GtkTextPendingScrol
   if (!gtk_text_mark_get_deleted (scroll->mark))
     gtk_text_buffer_delete_mark (gtk_text_mark_get_buffer (scroll->mark),
                                  scroll->mark);
-  g_object_unref (scroll->mark);
+  g_object_unref_and_context (scroll->mark);
   g_free (scroll);
 }
 
@@ -1660,7 +1660,7 @@ gtk_text_view_queue_scroll (GtkTextView 
                                               &iter,
                                               gtk_text_mark_get_left_gravity (mark));
 
-  g_object_ref (scroll->mark);
+  g_object_ref_and_context (scroll->mark);
   
   cancel_pending_scroll (text_view);
 
@@ -2560,9 +2560,9 @@ gtk_text_view_finalize (GObject *object)
     pango_tab_array_free (text_view->tabs);
   
   if (text_view->hadjustment)
-    g_object_unref (text_view->hadjustment);
+    g_object_unref_and_context (text_view->hadjustment);
   if (text_view->vadjustment)
-    g_object_unref (text_view->vadjustment);
+    g_object_unref_and_context (text_view->vadjustment);
 
   text_window_free (text_view->text_window);
 
@@ -2578,7 +2578,7 @@ gtk_text_view_finalize (GObject *object)
   if (text_view->bottom_window)
     text_window_free (text_view->bottom_window);
 
-  g_object_unref (text_view->im_context);
+  g_object_unref_with_context (text_view->im_context, text_view->im_context);
   
   (* G_OBJECT_CLASS (gtk_text_view_parent_class)->finalize) (object);
 }
@@ -5950,7 +5950,7 @@ gtk_text_view_destroy_layout (GtkTextVie
       gtk_text_view_stop_cursor_blink (text_view);
       gtk_text_view_end_selection_drag (text_view, NULL);
 
-      g_object_unref (text_view->layout);
+      g_object_unref_with_context (text_view->layout, text_view->layout);
       text_view->layout = NULL;
     }
 }
@@ -6468,7 +6468,7 @@ gtk_text_view_set_scroll_adjustments (Gt
       g_signal_handlers_disconnect_by_func (text_view->hadjustment,
 					    gtk_text_view_value_changed,
 					    text_view);
-      g_object_unref (text_view->hadjustment);
+      g_object_unref_and_context (text_view->hadjustment);
     }
 
   if (text_view->vadjustment && (text_view->vadjustment != vadj))
@@ -6476,13 +6476,13 @@ gtk_text_view_set_scroll_adjustments (Gt
       g_signal_handlers_disconnect_by_func (text_view->vadjustment,
 					    gtk_text_view_value_changed,
 					    text_view);
-      g_object_unref (text_view->vadjustment);
+      g_object_unref_and_context (text_view->vadjustment);
     }
 
   if (text_view->hadjustment != hadj)
     {
       text_view->hadjustment = hadj;
-      g_object_ref_sink (text_view->hadjustment);
+      g_object_ref_sink_and_context (text_view->hadjustment);
       
       g_signal_connect (text_view->hadjustment, "value_changed",
                         G_CALLBACK (gtk_text_view_value_changed),
@@ -6493,7 +6493,7 @@ gtk_text_view_set_scroll_adjustments (Gt
   if (text_view->vadjustment != vadj)
     {
       text_view->vadjustment = vadj;
-      g_object_ref_sink (text_view->vadjustment);
+      g_object_ref_sink_and_context (text_view->vadjustment);
       
       g_signal_connect (text_view->vadjustment, "value_changed",
                         G_CALLBACK (gtk_text_view_value_changed),
@@ -7273,21 +7273,21 @@ popup_targets_received (GtkClipboard    
 	}
     }
 
-  g_object_unref (text_view);
-  g_free (info);
+  g_object_unref_and_context (info->text_view);
+  g_slice_free (PopupInfo, info);
 }
 
 static void
 gtk_text_view_do_popup (GtkTextView    *text_view,
                         GdkEventButton *event)
 {
-  PopupInfo *info = g_new (PopupInfo, 1);
+  PopupInfo *info = g_slice_new (PopupInfo);
 
   /* In order to know what entries we should make sensitive, we
    * ask for the current targets of the clipboard, and when
    * we get them, then we actually pop up the menu.
    */
-  info->text_view = g_object_ref (text_view);
+  info->text_view = g_object_ref_with_context (text_view, &info->text_view);
   
   if (event)
     {
@@ -8189,8 +8189,8 @@ text_view_child_new_anchored (GtkWidget 
   vc->from_top_of_line = 0;
   vc->from_left_of_buffer = 0;
   
-  g_object_ref (vc->widget);
-  g_object_ref (vc->anchor);
+  g_object_ref_and_context (vc->widget);
+  g_object_ref_and_context (vc->anchor);
 
   g_object_set_data (G_OBJECT (child),
                      I_("gtk-text-view-child"),
@@ -8217,7 +8217,7 @@ text_view_child_new_window (GtkWidget   
   vc->from_top_of_line = 0;
   vc->from_left_of_buffer = 0;
  
-  g_object_ref (vc->widget);
+  g_object_ref_and_context (vc->widget);
 
   vc->type = type;
   vc->x = x;
@@ -8240,10 +8240,10 @@ text_view_child_free (GtkTextViewChild *
     {
       gtk_text_child_anchor_unregister_child (child->anchor,
                                               child->widget);
-      g_object_unref (child->anchor);
+      g_object_unref_and_context (child->anchor);
     }
 
-  g_object_unref (child->widget);
+  g_object_unref_and_context (child->widget);
 
   g_free (child);
 }
Index: gtk/gtktoolbar.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolbar.c,v
retrieving revision 1.183
diff -u -p -r1.183 gtktoolbar.c
--- gtk/gtktoolbar.c	16 May 2006 16:51:27 -0000	1.183
+++ gtk/gtktoolbar.c	19 Jul 2006 22:43:36 -0000
@@ -834,7 +834,7 @@ gtk_toolbar_realize (GtkWidget *widget)
   attributes_mask = GDK_WA_X | GDK_WA_Y;
   
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
   widget->style = gtk_style_attach (widget->style, widget->window);
   
   priv->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
@@ -2065,7 +2065,7 @@ gtk_toolbar_screen_changed (GtkWidget *w
     {
       g_signal_handler_disconnect (old_settings, priv->settings_connection);
 
-      g_object_unref (old_settings);
+      g_object_unref_with_context (old_settings, &priv->settings);
     }
 
   if (settings)
@@ -2075,7 +2075,7 @@ gtk_toolbar_screen_changed (GtkWidget *w
                           G_CALLBACK (settings_change_notify),
                           toolbar);
 
-      priv->settings = g_object_ref (settings);
+      priv->settings = g_object_ref_with_context (settings, &priv->settings);
     }
   else
     priv->settings = NULL;
@@ -3995,10 +3995,10 @@ toolbar_content_remove (ToolbarContent *
       
       if (child->type != GTK_TOOLBAR_CHILD_SPACE)
 	{
-	  g_object_ref (child->widget);
+	  g_object_ref_and_context (child->widget);
 	  gtk_widget_unparent (child->widget);
 	  gtk_widget_destroy (child->widget);
-	  g_object_unref (child->widget);
+	  g_object_unref_and_context (child->widget);
 	}
       
       toolbar->children = g_list_remove (toolbar->children, child);
Index: gtk/gtktoolitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktoolitem.c,v
retrieving revision 1.35
diff -u -p -r1.35 gtktoolitem.c
--- gtk/gtktoolitem.c	14 May 2006 04:25:31 -0000	1.35
+++ gtk/gtktoolitem.c	19 Jul 2006 22:43:37 -0000
@@ -367,7 +367,7 @@ gtk_tool_item_realize (GtkWidget *widget
   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
 
   widget->window = gtk_widget_get_parent_window (widget);
-  g_object_ref (widget->window);
+  g_object_ref_and_context (widget->window);
 
   if (toolitem->priv->use_drag_window)
     create_drag_window(toolitem);
Index: gtk/gtktooltips.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktooltips.c,v
retrieving revision 1.76
diff -u -p -r1.76 gtktooltips.c
--- gtk/gtktooltips.c	6 Jul 2006 05:14:03 -0000	1.76
+++ gtk/gtktooltips.c	19 Jul 2006 22:43:38 -0000
@@ -120,7 +120,6 @@ gtk_tooltips_destroy_data (GtkTooltipsDa
 					tooltipsdata);
 
   g_object_set_data (G_OBJECT (tooltipsdata->widget), I_(tooltips_data_key), NULL);
-  g_object_unref (tooltipsdata->widget);
   g_free (tooltipsdata);
 }
 
@@ -299,6 +298,8 @@ gtk_tooltips_set_tip (GtkTooltips *toolt
 	gtk_tooltips_widget_remove (tooltipsdata->widget, tooltipsdata);
       return;
     }
+
+  g_object_ref_and_context (tooltips);
   
   if (tooltips->active_tips_data 
       && tooltips->active_tips_data->widget == widget
@@ -314,14 +315,15 @@ gtk_tooltips_set_tip (GtkTooltips *toolt
     }
   else 
     {
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       
       if (tooltipsdata)
         gtk_tooltips_widget_remove (tooltipsdata->widget, tooltipsdata);
       
       tooltipsdata = g_new0 (GtkTooltipsData, 1);
       
-      tooltipsdata->tooltips = tooltips;
+      tooltipsdata->tooltips = g_object_ref_sink_with_context (tooltips,
+	  &tooltipsdata->tooltips);
       tooltipsdata->widget = widget;
 
       tooltipsdata->tip_text = g_strdup (tip_text);
@@ -333,9 +335,6 @@ gtk_tooltips_set_tip (GtkTooltips *toolt
                               G_CALLBACK (gtk_tooltips_event_handler),
 			      tooltipsdata);
 
-      g_object_set_data (G_OBJECT (widget), I_(tooltips_data_key),
-                         tooltipsdata);
-
       g_signal_connect (widget, "unmap",
 			G_CALLBACK (gtk_tooltips_widget_unmap),
 			tooltipsdata);
@@ -345,9 +344,16 @@ gtk_tooltips_set_tip (GtkTooltips *toolt
 			tooltipsdata);
 
       g_signal_connect (widget, "destroy",
-                        G_CALLBACK (gtk_tooltips_widget_remove),
+			G_CALLBACK (gtk_tooltips_widget_remove),
 			tooltipsdata);
+
+      g_object_set_data (G_OBJECT (widget),
+			I_(tooltips_data_key), tooltipsdata);
+
+      g_object_unref_and_context (widget);
     }
+
+  g_object_unref_and_context (tooltips);
 }
 
 static gint
@@ -376,7 +382,7 @@ gtk_tooltips_draw_tips (GtkTooltips *too
   GdkScreen *pointer_screen;
   gint monitor_num, px, py;
   GdkRectangle monitor;
-  GtkWindow *toplevel;
+  GtkWidget *toplevel;
 
   if (!tooltips->tip_window)
     gtk_tooltips_force_window (tooltips);
@@ -440,7 +446,7 @@ gtk_tooltips_draw_tips (GtkTooltips *too
 
   toplevel = gtk_widget_get_toplevel (widget);
   if (toplevel && GTK_IS_WINDOW (toplevel))
-    gtk_window_set_transient_for (tooltips->tip_window, toplevel);
+    gtk_window_set_transient_for (GTK_WINDOW(tooltips->tip_window), GTK_WINDOW(toplevel));
   
   gtk_window_move (GTK_WINDOW (tooltips->tip_window), x, y);
   gtk_widget_show (tooltips->tip_window);
@@ -736,6 +742,8 @@ gtk_tooltips_widget_remove (GtkWidget *w
   gtk_tooltips_widget_unmap (widget, data);
   tooltips->tips_data_list = g_list_remove (tooltips->tips_data_list,
 					    tooltipsdata);
+  g_object_unref_and_context (tooltipsdata->tooltips);
+
   gtk_tooltips_destroy_data (tooltipsdata);
 }
 
Index: gtk/gtktreedatalist.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreedatalist.c,v
retrieving revision 1.36
diff -u -p -r1.36 gtktreedatalist.c
--- gtk/gtktreedatalist.c	29 Dec 2005 05:26:08 -0000	1.36
+++ gtk/gtktreedatalist.c	19 Jul 2006 22:43:38 -0000
@@ -52,7 +52,7 @@ _gtk_tree_data_list_free (GtkTreeDataLis
       if (g_type_is_a (column_headers [i], G_TYPE_STRING))
 	g_free ((gchar *) tmp->data.v_pointer);
       else if (g_type_is_a (column_headers [i], G_TYPE_OBJECT) && tmp->data.v_pointer != NULL)
-	g_object_unref (tmp->data.v_pointer);
+	g_object_unref_and_context (tmp->data.v_pointer);
       else if (g_type_is_a (column_headers [i], G_TYPE_BOXED) && tmp->data.v_pointer != NULL)
 	g_boxed_free (column_headers [i], (gpointer) tmp->data.v_pointer);
 
@@ -237,8 +237,10 @@ _gtk_tree_data_list_value_to_node (GtkTr
       break;
     case G_TYPE_OBJECT:
       if (list->data.v_pointer)
-	g_object_unref (list->data.v_pointer);
-      list->data.v_pointer = g_value_dup_object (value);
+	g_object_unref_and_context (list->data.v_pointer);
+      list->data.v_pointer = g_value_get_object (value);
+      if (list->data.v_pointer)
+	g_object_ref_and_context (list->data.v_pointer);
       break;
     case G_TYPE_BOXED:
       if (list->data.v_pointer)
@@ -287,7 +289,7 @@ _gtk_tree_data_list_node_copy (GtkTreeDa
     case G_TYPE_INTERFACE:
       new_list->data.v_pointer = list->data.v_pointer;
       if (new_list->data.v_pointer)
-	g_object_ref (new_list->data.v_pointer);
+	g_object_ref_and_context (new_list->data.v_pointer);
       break;
     case G_TYPE_BOXED:
       if (list->data.v_pointer)
Index: gtk/gtktreeitem.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeitem.c,v
retrieving revision 1.68
diff -u -p -r1.68 gtktreeitem.c
--- gtk/gtktreeitem.c	23 Nov 2005 18:06:56 -0000	1.68
+++ gtk/gtktreeitem.c	19 Jul 2006 22:43:39 -0000
@@ -383,8 +383,8 @@ gtk_tree_item_add_pixmaps (GtkTreeItem *
     {
       pixmap_node = g_new (GtkTreePixmaps, 1);
 
-      pixmap_node->colormap = colormap;
-      g_object_ref (colormap);
+      pixmap_node->colormap = g_object_ref_with_context (colormap,
+	  &pixmap_node->colormap);
 
       pixmap_node->refcount = 1;
 
@@ -424,7 +424,7 @@ gtk_tree_item_remove_pixmaps (GtkTreeIte
       
       if (--pixmap_node->refcount == 0)
 	{
-	  g_object_unref (pixmap_node->colormap);
+	  g_object_unref_and_context (pixmap_node->colormap);
 	  g_object_unref (pixmap_node->pixmap_plus);
 	  g_object_unref (pixmap_node->mask_plus);
 	  g_object_unref (pixmap_node->pixmap_minus);
@@ -704,7 +704,7 @@ gtk_tree_item_expose_child (GtkWidget *c
     {
       GdkEvent *child_event = gdk_event_new (GDK_EXPOSE);
       child_event->expose = *data->event;
-      g_object_ref (child_event->expose.window);
+      g_object_ref_and_context (child_event->expose.window);
 
       child_event->expose.region = gtk_widget_region_intersect (child,
 								data->event->region);
Index: gtk/gtktreemodel.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodel.c,v
retrieving revision 1.128
diff -u -p -r1.128 gtktreemodel.c
--- gtk/gtktreemodel.c	4 May 2006 12:17:12 -0000	1.128
+++ gtk/gtktreemodel.c	19 Jul 2006 22:43:41 -0000
@@ -382,7 +382,7 @@ GtkTreePath *
 gtk_tree_path_new (void)
 {
   GtkTreePath *retval;
-  retval = g_new (GtkTreePath, 1);
+  retval = g_slice_new (GtkTreePath);
   retval->depth = 0;
   retval->indices = NULL;
 
@@ -623,7 +623,7 @@ gtk_tree_path_free (GtkTreePath *path)
     return;
 
   g_free (path->indices);
-  g_free (path);
+  g_slice_free (GtkTreePath, path);
 }
 
 /**
@@ -641,7 +641,7 @@ gtk_tree_path_copy (const GtkTreePath *p
 
   g_return_val_if_fail (path != NULL, NULL);
 
-  retval = g_new (GtkTreePath, 1);
+  retval = g_slice_new (GtkTreePath);
   retval->depth = path->depth;
   retval->indices = g_new (gint, path->depth);
   memcpy (retval->indices, path->indices, path->depth * sizeof (gint));
@@ -1669,7 +1669,7 @@ release_row_references (gpointer data)
     }
 
   g_slist_free (refs->list);
-  g_free (refs);
+  g_slice_free (RowRefList, refs);
 }
 
 static void
@@ -1952,10 +1952,10 @@ gtk_tree_row_reference_new_proxy (GObjec
     }
 
   /* Make the row reference */
-  reference = g_new (GtkTreeRowReference, 1);
+  reference = g_slice_new (GtkTreeRowReference);
 
-  g_object_ref (proxy);
-  g_object_ref (model);
+  g_object_ref_with_context (proxy, &reference->proxy);
+  g_object_ref_with_context (model, &reference->model);
   reference->proxy = proxy;
   reference->model = model;
   reference->path = gtk_tree_path_copy (path);
@@ -1964,7 +1964,7 @@ gtk_tree_row_reference_new_proxy (GObjec
 
   if (refs == NULL)
     {
-      refs = g_new (RowRefList, 1);
+      refs = g_slice_new (RowRefList);
       refs->list = NULL;
 
       g_object_set_data_full (G_OBJECT (proxy),
@@ -2092,9 +2092,9 @@ gtk_tree_row_reference_free (GtkTreeRowR
       gtk_tree_path_free (reference->path);
     }
 
-  g_object_unref (reference->proxy);
-  g_object_unref (reference->model);
-  g_free (reference);
+  g_object_unref_and_context (reference->proxy);
+  g_object_unref_and_context (reference->model);
+  g_slice_free (GtkTreeRowReference, reference);
 }
 
 /**
Index: gtk/gtktreemodelfilter.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelfilter.c,v
retrieving revision 1.46
diff -u -p -r1.46 gtktreemodelfilter.c
--- gtk/gtktreemodelfilter.c	12 Jun 2006 14:48:43 -0000	1.46
+++ gtk/gtktreemodelfilter.c	19 Jul 2006 22:43:44 -0000
@@ -2717,7 +2717,7 @@ gtk_tree_model_filter_set_model (GtkTree
         gtk_tree_model_filter_free_level (filter, filter->priv->root);
 
       filter->priv->root = NULL;
-      g_object_unref (filter->priv->child_model);
+      g_object_unref_and_context (filter->priv->child_model);
       filter->priv->visible_column = -1;
 
       /* FIXME: do we need to destroy more here? */
@@ -2727,7 +2727,7 @@ gtk_tree_model_filter_set_model (GtkTree
 
   if (child_model)
     {
-      g_object_ref (filter->priv->child_model);
+      g_object_ref_and_context (filter->priv->child_model);
       filter->priv->changed_id =
         g_signal_connect (child_model, "row_changed",
                           G_CALLBACK (gtk_tree_model_filter_row_changed),
Index: gtk/gtktreemodelsort.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreemodelsort.c,v
retrieving revision 1.105
diff -u -p -r1.105 gtktreemodelsort.c
--- gtk/gtktreemodelsort.c	2 Jul 2006 14:48:00 -0000	1.105
+++ gtk/gtktreemodelsort.c	19 Jul 2006 22:43:47 -0000
@@ -1837,7 +1837,7 @@ gtk_tree_model_sort_set_model (GtkTreeMo
                                GtkTreeModel     *child_model)
 {
   if (child_model)
-    g_object_ref (child_model);
+    g_object_ref_with_context (child_model, &tree_model_sort->child_model);
 
   if (tree_model_sort->child_model)
     {
@@ -1858,7 +1858,7 @@ gtk_tree_model_sort_set_model (GtkTreeMo
       tree_model_sort->root = NULL;
       _gtk_tree_data_list_header_free (tree_model_sort->sort_list);
       tree_model_sort->sort_list = NULL;
-      g_object_unref (tree_model_sort->child_model);
+      g_object_unref_and_context (tree_model_sort->child_model);
     }
 
   tree_model_sort->child_model = child_model;
Index: gtk/gtktreeselection.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeselection.c,v
retrieving revision 1.87
diff -u -p -r1.87 gtktreeselection.c
--- gtk/gtktreeselection.c	2 Jun 2006 18:55:59 -0000	1.87
+++ gtk/gtktreeselection.c	19 Jul 2006 22:43:48 -0000
@@ -616,7 +616,7 @@ gtk_tree_selection_selected_foreach (Gtk
     node = node->left;
 
   model = selection->tree_view->priv->model;
-  g_object_ref (model);
+  g_object_ref_and_context (model);
 
   /* connect to signals to monitor changes in treemodel */
   inserted_id = g_signal_connect_swapped (model, "row_inserted",
@@ -697,7 +697,7 @@ out:
   g_signal_handler_disconnect (model, deleted_id);
   g_signal_handler_disconnect (model, reordered_id);
   g_signal_handler_disconnect (selection->tree_view, changed_id);
-  g_object_unref (model);
+  g_object_unref_and_context (model);
 
   /* check if we have to spew a scary message */
   if (stop)
Index: gtk/gtktreeview.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeview.c,v
retrieving revision 1.563
diff -u -p -r1.563 gtktreeview.c
--- gtk/gtktreeview.c	18 Jul 2006 13:33:26 -0000	1.563
+++ gtk/gtktreeview.c	19 Jul 2006 22:44:02 -0000
@@ -2760,11 +2760,11 @@ gtk_tree_view_button_release_drag_column
   gdk_display_keyboard_ungrab (gtk_widget_get_display (widget), GDK_CURRENT_TIME);
 
   /* Move the button back */
-  g_object_ref (tree_view->priv->drag_column->button);
+  g_object_ref_and_context (tree_view->priv->drag_column->button);
   gtk_container_remove (GTK_CONTAINER (tree_view), tree_view->priv->drag_column->button);
   gtk_widget_set_parent_window (tree_view->priv->drag_column->button, tree_view->priv->header_window);
   gtk_widget_set_parent (tree_view->priv->drag_column->button, GTK_WIDGET (tree_view));
-  g_object_unref (tree_view->priv->drag_column->button);
+  g_object_unref_and_context (tree_view->priv->drag_column->button);
   gtk_widget_queue_resize (widget);
   if (tree_view->priv->drag_column->resizable)
     {
@@ -5260,8 +5260,8 @@ gtk_tree_view_key_press (GtkWidget   *wi
       /* Make a copy of the current text */
       old_text = g_strdup (gtk_entry_get_text (GTK_ENTRY (tree_view->priv->search_entry)));
       new_event = gdk_event_copy ((GdkEvent *) event);
-      g_object_unref (((GdkEventKey *) new_event)->window);
-      ((GdkEventKey *) new_event)->window = g_object_ref (tree_view->priv->search_window->window);
+      g_object_unref_and_context (((GdkEventKey *) new_event)->window);
+      ((GdkEventKey *) new_event)->window = g_object_ref_with_context (tree_view->priv->search_window->window, &((GdkEventKey *) new_event)->window);
       gtk_widget_realize (tree_view->priv->search_window);
 
       popup_menu_id = g_signal_connect (tree_view->priv->search_entry, 
@@ -9195,7 +9195,7 @@ _gtk_tree_view_column_start_drag (GtkTre
 
   send_event = gdk_event_new (GDK_LEAVE_NOTIFY);
   send_event->crossing.send_event = TRUE;
-  send_event->crossing.window = g_object_ref (GTK_BUTTON (column->button)->event_window);
+  send_event->crossing.window = g_object_ref_with_context (GTK_BUTTON (column->button)->event_window, &send_event->crossing.window);
   send_event->crossing.subwindow = NULL;
   send_event->crossing.detail = GDK_NOTIFY_ANCESTOR;
   send_event->crossing.time = GDK_CURRENT_TIME;
@@ -9204,7 +9204,7 @@ _gtk_tree_view_column_start_drag (GtkTre
   gdk_event_free (send_event);
 
   send_event = gdk_event_new (GDK_BUTTON_RELEASE);
-  send_event->button.window = g_object_ref (gdk_screen_get_root_window (screen));
+  send_event->button.window = g_object_ref_with_context (gdk_screen_get_root_window (screen), &send_event->button.window);
   send_event->button.send_event = TRUE;
   send_event->button.time = GDK_CURRENT_TIME;
   send_event->button.x = -1;
@@ -9226,11 +9226,11 @@ _gtk_tree_view_column_start_drag (GtkTre
 			  column->button->allocation.height);
 
   /* Kids, don't try this at home */
-  g_object_ref (column->button);
+  g_object_ref_and_context (column->button);
   gtk_container_remove (GTK_CONTAINER (tree_view), column->button);
   gtk_widget_set_parent_window (column->button, tree_view->priv->drag_window);
   gtk_widget_set_parent (column->button, GTK_WIDGET (tree_view));
-  g_object_unref (column->button);
+  g_object_unref_and_context (column->button);
 
   tree_view->priv->drag_column_x = column->button->allocation.x;
   allocation = column->button->allocation;
@@ -9983,7 +9983,7 @@ send_focus_change (GtkWidget *widget,
 {
   GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
    
  if (in)
     GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
@@ -9991,14 +9991,14 @@ send_focus_change (GtkWidget *widget,
     GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
 
   fevent->focus_change.type = GDK_FOCUS_CHANGE;
-  fevent->focus_change.window = g_object_ref (widget->window);
+  fevent->focus_change.window = g_object_ref_with_context (widget->window, &fevent->focus_change.window);
   fevent->focus_change.in = in;
   
   gtk_widget_event (widget, fevent);
   
   g_object_notify (G_OBJECT (widget), "has-focus");
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
   gdk_event_free (fevent);
 }
 
@@ -10448,7 +10448,7 @@ gtk_tree_view_set_model (GtkTreeView  *t
 
       tree_view->priv->scroll_to_column = NULL;
 
-      g_object_unref (tree_view->priv->model);
+      g_object_unref_and_context (tree_view->priv->model);
 
       tree_view->priv->search_column = -1;
       tree_view->priv->fixed_height_check = 0;
@@ -10479,7 +10479,7 @@ gtk_tree_view_set_model (GtkTreeView  *t
 	    }
 	}
 
-      g_object_ref (tree_view->priv->model);
+      g_object_ref_and_context (tree_view->priv->model);
       g_signal_connect (tree_view->priv->model,
 			"row_changed",
 			G_CALLBACK (gtk_tree_view_row_changed),
@@ -13565,7 +13565,7 @@ gtk_tree_view_set_search_entry (GtkTreeV
 					    G_CALLBACK (gtk_tree_view_search_key_press_event),
 					    tree_view);
 
-      g_object_unref (tree_view->priv->search_entry);
+      g_object_unref_and_context (tree_view->priv->search_entry);
     }
   else if (tree_view->priv->search_window)
     {
@@ -13576,7 +13576,7 @@ gtk_tree_view_set_search_entry (GtkTreeV
 
   if (entry)
     {
-      tree_view->priv->search_entry = g_object_ref (entry);
+      tree_view->priv->search_entry = g_object_ref_with_context (entry, &tree_view->priv->search_entry);
       tree_view->priv->search_custom_entry_set = TRUE;
 
       if (tree_view->priv->search_entry_changed_id == 0)
Index: gtk/gtktreeviewcolumn.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtktreeviewcolumn.c,v
retrieving revision 1.180
diff -u -p -r1.180 gtktreeviewcolumn.c
--- gtk/gtktreeviewcolumn.c	30 May 2006 09:29:49 -0000	1.180
+++ gtk/gtktreeviewcolumn.c	19 Jul 2006 22:44:06 -0000
@@ -936,7 +936,7 @@ gtk_tree_view_column_update_button (GtkT
    * left otherwise; do this by packing boxes, so flipping text direction will
    * reverse things
    */
-  g_object_ref (arrow);
+  g_object_ref_and_context (arrow);
   gtk_container_remove (GTK_CONTAINER (hbox), arrow);
 
   if (tree_column->xalign <= 0.5)
@@ -949,7 +949,7 @@ gtk_tree_view_column_update_button (GtkT
       /* move it to the front */
       gtk_box_reorder_child (GTK_BOX (hbox), arrow, 0);
     }
-  g_object_unref (arrow);
+  g_object_unref_and_context (arrow);
 
   if (GTK_IS_TREE_SORTABLE (model) && tree_column->sort_column_id >= 0)
     gtk_widget_show (arrow);
Index: gtk/gtkuimanager.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkuimanager.c,v
retrieving revision 1.102
diff -u -p -r1.102 gtkuimanager.c
--- gtk/gtkuimanager.c	6 Jul 2006 05:14:03 -0000	1.102
+++ gtk/gtkuimanager.c	19 Jul 2006 22:44:09 -0000
@@ -373,6 +373,11 @@ gtk_ui_manager_init (GtkUIManager *self)
 }
 
 static void
+action_group_unref (gpointer ptr, gpointer ctx)
+{
+  g_object_unref_with_context (ptr, ctx);
+}
+static void
 gtk_ui_manager_finalize (GObject *object)
 {
   GtkUIManager *self = GTK_UI_MANAGER (object);
@@ -390,11 +395,11 @@ gtk_ui_manager_finalize (GObject *object
   self->private_data->root_node = NULL;
   
   g_list_foreach (self->private_data->action_groups,
-                  (GFunc) g_object_unref, NULL);
+                  action_group_unref, &self->private_data->action_groups);
   g_list_free (self->private_data->action_groups);
   self->private_data->action_groups = NULL;
 
-  g_object_unref (self->private_data->accel_group);
+  g_object_unref_with_context (self->private_data->accel_group, self->private_data->accel_group);
   self->private_data->accel_group = NULL;
 
   G_OBJECT_CLASS (gtk_ui_manager_parent_class)->finalize (object);
@@ -601,7 +606,7 @@ gtk_ui_manager_insert_action_group (GtkU
   g_return_if_fail (g_list_find (self->private_data->action_groups, 
 				 action_group) == NULL);
 
-  g_object_ref (action_group);
+  g_object_ref_with_context (action_group, &self->private_data->action_groups);
   self->private_data->action_groups = 
     g_list_insert (self->private_data->action_groups, action_group, pos);
   g_object_connect (action_group,
@@ -645,7 +650,7 @@ gtk_ui_manager_remove_action_group (GtkU
                        "any_signal::pre_activate", G_CALLBACK (cb_proxy_pre_activate), self,
                        "any_signal::post_activate", G_CALLBACK (cb_proxy_post_activate), self, 
                        NULL);
-  g_object_unref (action_group);
+  g_object_unref_with_context (action_group, &self->private_data->action_groups);
 
   /* dirty all nodes, as action bindings may change */
   dirty_all_nodes (self);
@@ -967,11 +972,11 @@ free_node (GNode *node)
   g_list_free (info->uifiles);
 
   if (info->action)
-    g_object_unref (info->action);
+    g_object_unref_and_context (info->action);
   if (info->proxy)
-    g_object_unref (info->proxy);
+    g_object_unref_and_context (info->proxy);
   if (info->extra)
-    g_object_unref (info->extra);
+    g_object_unref_and_context (info->extra);
   g_free (info->name);
   g_slice_free (Node, info);
 
@@ -2171,7 +2176,7 @@ update_node (GtkUIManager *self, 
       if (info->proxy == NULL)
 	{
 	  info->proxy = gtk_menu_bar_new ();
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_name (info->proxy, info->name);
 	  gtk_widget_show (info->proxy);
 	  g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
@@ -2181,7 +2186,7 @@ update_node (GtkUIManager *self, 
       if (info->proxy == NULL) 
 	{
 	  info->proxy = gtk_menu_new ();
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	}
       gtk_widget_set_name (info->proxy, info->name);
       break;
@@ -2199,7 +2204,7 @@ update_node (GtkUIManager *self, 
 		prev_submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (info->proxy));
 		if (prev_submenu)
 		  {
-		    g_object_ref (prev_submenu);
+		    g_object_ref_and_context (prev_submenu);
 		    gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy), NULL);
 		}
 	      }
@@ -2207,7 +2212,7 @@ update_node (GtkUIManager *self, 
 	    gtk_action_disconnect_proxy (info->action, info->proxy);
 	    gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				  info->proxy);
-	    g_object_unref (info->proxy);
+	    g_object_unref_and_context (info->proxy);
 	    info->proxy = NULL;
 	  }
 	/* create proxy if needed ... */
@@ -2232,7 +2237,7 @@ update_node (GtkUIManager *self, 
 	    if (NODE_INFO (node->parent)->type == NODE_TYPE_TOOLITEM)
 	      {
 		info->proxy = menu;
-		g_object_ref_sink (info->proxy);
+		g_object_ref_sink_and_context (info->proxy);
 		gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (NODE_INFO (node->parent)->proxy),
 					       menu);
 	      }
@@ -2243,7 +2248,7 @@ update_node (GtkUIManager *self, 
 		
 		find_menu_position (node, &menushell, &pos);
 		info->proxy = gtk_action_create_menu_item (action);
-		g_object_ref_sink (info->proxy);
+		g_object_ref_sink_and_context (info->proxy);
 		g_signal_connect (info->proxy, "notify::visible",
 				  G_CALLBACK (update_smart_separators), NULL);
 		gtk_widget_set_name (info->proxy, info->name);
@@ -2259,7 +2264,7 @@ update_node (GtkUIManager *self, 
 	  {
 	    gtk_menu_item_set_submenu (GTK_MENU_ITEM (info->proxy),
 				       prev_submenu);
-	    g_object_unref (prev_submenu);
+	    g_object_unref_and_context (prev_submenu);
 	  }
 	
 	if (GTK_IS_MENU (info->proxy))
@@ -2286,7 +2291,7 @@ update_node (GtkUIManager *self, 
       if (info->proxy == NULL)
 	{
 	  info->proxy = gtk_toolbar_new ();
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_name (info->proxy, info->name);
 	  gtk_widget_show (info->proxy);
 	  g_signal_emit (self, ui_manager_signals[ADD_WIDGET], 0, info->proxy);
@@ -2301,14 +2306,14 @@ update_node (GtkUIManager *self, 
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				    info->proxy);
-	      g_object_unref (info->proxy);
+	      g_object_unref_and_context (info->proxy);
 	      info->proxy = NULL;
 	    }
 	  if (info->extra)
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->extra->parent),
 				    info->extra);
-	      g_object_unref (info->extra);
+	      g_object_unref_and_context (info->extra);
 	      info->extra = NULL;
 	    }
 	}
@@ -2319,7 +2324,7 @@ update_node (GtkUIManager *self, 
 	  
 	  find_menu_position (node, &menushell, &pos);
 	  info->proxy = gtk_separator_menu_item_new ();
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  g_object_set_data (G_OBJECT (info->proxy),
 			     I_("gtk-separator-mode"),
 			     GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
@@ -2328,7 +2333,7 @@ update_node (GtkUIManager *self, 
 				 NODE_INFO (node)->proxy, pos);
 	  
 	  info->extra = gtk_separator_menu_item_new ();
-	  g_object_ref_sink (info->extra);
+	  g_object_ref_sink_and_context (info->extra);
 	  g_object_set_data (G_OBJECT (info->extra),
 			     I_("gtk-separator-mode"),
 			     GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
@@ -2346,14 +2351,14 @@ update_node (GtkUIManager *self, 
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				    info->proxy);
-	      g_object_unref (info->proxy);
+	      g_object_unref_and_context (info->proxy);
 	      info->proxy = NULL;
 	    }
 	  if (info->extra)
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->extra->parent),
 				    info->extra);
-	      g_object_unref (info->extra);
+	      g_object_unref_and_context (info->extra);
 	      info->extra = NULL;
 	    }
 	}
@@ -2367,7 +2372,7 @@ update_node (GtkUIManager *self, 
 	  item = gtk_separator_tool_item_new ();
 	  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
 	  info->proxy = GTK_WIDGET (item);
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  g_object_set_data (G_OBJECT (info->proxy),
 			     I_("gtk-separator-mode"),
 			     GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
@@ -2376,7 +2381,7 @@ update_node (GtkUIManager *self, 
 	  item = gtk_separator_tool_item_new ();
 	  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos+1);
 	  info->extra = GTK_WIDGET (item);
-	  g_object_ref_sink (info->extra);
+	  g_object_ref_sink_and_context (info->extra);
 	  g_object_set_data (G_OBJECT (info->extra),
 			     I_("gtk-separator-mode"),
 			     GINT_TO_POINTER (SEPARATOR_MODE_HIDDEN));
@@ -2394,7 +2399,7 @@ update_node (GtkUIManager *self, 
 	  gtk_action_disconnect_proxy (info->action, info->proxy);
 	  gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				info->proxy);
-	  g_object_unref (info->proxy);
+	  g_object_unref_and_context (info->proxy);
 	  info->proxy = NULL;
 	}
       /* create proxy if needed ... */
@@ -2405,7 +2410,7 @@ update_node (GtkUIManager *self, 
 	  
 	  find_menu_position (node, &menushell, &pos);
 	  info->proxy = gtk_action_create_menu_item (action);
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_name (info->proxy, info->name);
 	  
 	  gtk_menu_shell_insert (GTK_MENU_SHELL (menushell),
@@ -2442,7 +2447,7 @@ update_node (GtkUIManager *self, 
 	  gtk_action_disconnect_proxy (info->action, info->proxy);
 	  gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				info->proxy);
-	  g_object_unref (info->proxy);
+	  g_object_unref_and_context (info->proxy);
 	  info->proxy = NULL;
 	}
       /* create proxy if needed ... */
@@ -2453,7 +2458,7 @@ update_node (GtkUIManager *self, 
 	  
 	  find_toolbar_position (node, &toolbar, &pos);
 	  info->proxy = gtk_action_create_tool_item (action);
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_name (info->proxy, info->name);
 	  
 	  gtk_toolbar_insert (GTK_TOOLBAR (toolbar),
@@ -2494,7 +2499,7 @@ update_node (GtkUIManager *self, 
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				    info->proxy);
-	      g_object_unref (info->proxy);
+	      g_object_unref_and_context (info->proxy);
 	      info->proxy = NULL;
 	    }
 	  
@@ -2502,7 +2507,7 @@ update_node (GtkUIManager *self, 
 	  item  = gtk_separator_tool_item_new ();
 	  gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, pos);
 	  info->proxy = GTK_WIDGET (item);
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_no_show_all (info->proxy, TRUE);
 	  if (info->expand)
 	    {
@@ -2528,13 +2533,13 @@ update_node (GtkUIManager *self, 
 	    {
 	      gtk_container_remove (GTK_CONTAINER (info->proxy->parent),
 				    info->proxy);
-	      g_object_unref (info->proxy);
+	      g_object_unref_and_context (info->proxy);
 	      info->proxy = NULL;
 	    }
 	  
 	  find_menu_position (node, &menushell, &pos);
 	  info->proxy = gtk_separator_menu_item_new ();
-	  g_object_ref_sink (info->proxy);
+	  g_object_ref_sink_and_context (info->proxy);
 	  gtk_widget_set_no_show_all (info->proxy, TRUE);
 	  g_object_set_data (G_OBJECT (info->proxy),
 			     I_("gtk-separator-mode"),
@@ -2550,9 +2555,9 @@ update_node (GtkUIManager *self, 
     }
   
   if (action)
-    g_object_ref (action);
+    g_object_ref_with_context (action, &info->action);
   if (info->action)
-    g_object_unref (info->action);
+    g_object_unref_and_context (info->action);
   info->action = action;
 
  recurse_children:
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.442
diff -u -p -r1.442 gtkwidget.c
--- gtk/gtkwidget.c	6 Jul 2006 05:14:03 -0000	1.442
+++ gtk/gtkwidget.c	19 Jul 2006 22:44:17 -0000
@@ -238,7 +238,6 @@ static void gtk_widget_get_draw_rectangl
 /* --- variables --- */
 static gpointer         gtk_widget_parent_class = NULL;
 static guint            widget_signals[LAST_SIGNAL] = { 0 };
-static GtkStyle        *gtk_default_style = NULL;
 static GSList          *colormap_stack = NULL;
 static guint            composite_child_stack = 0;
 static GtkTextDirection gtk_default_direction = GTK_TEXT_DIR_LTR;
@@ -1870,7 +1869,7 @@ gtk_widget_init (GtkWidget *widget)
   GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
 
   widget->style = gtk_widget_get_default_style ();
-  g_object_ref (widget->style);
+  g_object_ref_and_context (widget->style);
 }
 
 
@@ -1903,9 +1902,9 @@ gtk_widget_freeze_child_notify (GtkWidge
   if (!G_OBJECT (widget)->ref_count)
     return;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -1931,7 +1930,7 @@ gtk_widget_child_notify (GtkWidget    *w
   if (!G_OBJECT (widget)->ref_count || !widget->parent)
     return;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
 				    child_property,
 				    G_OBJECT_TYPE (widget->parent),
@@ -1948,7 +1947,7 @@ gtk_widget_child_notify (GtkWidget    *w
       g_object_notify_queue_add (G_OBJECT (widget), nqueue, pspec);
       g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
     }
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -1968,14 +1967,14 @@ gtk_widget_thaw_child_notify (GtkWidget 
   if (!G_OBJECT (widget)->ref_count)
     return;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
   if (!nqueue || !nqueue->freeze_count)
     g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
 	       G_OBJECT_TYPE_NAME (widget), widget);
   else
     g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 
@@ -2084,7 +2083,7 @@ gtk_widget_unparent (GtkWidget *widget)
    * to emit hierarchy changed
    */
   if (GTK_WIDGET_ANCHORED (widget->parent))
-    g_object_ref (toplevel);
+    g_object_ref_and_context (toplevel);
   else
     toplevel = NULL;
 
@@ -2119,7 +2118,7 @@ gtk_widget_unparent (GtkWidget *widget)
   if (toplevel)
     {
       _gtk_widget_propagate_hierarchy_changed (widget, toplevel);
-      g_object_unref (toplevel);
+      g_object_unref_and_context (toplevel);
     }
       
   g_object_notify (G_OBJECT (widget), "parent");
@@ -2127,7 +2126,7 @@ gtk_widget_unparent (GtkWidget *widget)
   if (!widget->parent)
     g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
   g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
-  g_object_unref (widget);
+  g_object_unref_with_context (widget, &widget->parent);
 }
 
 /**
@@ -2206,12 +2205,12 @@ gtk_widget_show (GtkWidget *widget)
 {
   if (!GTK_WIDGET_VISIBLE (widget))
     {
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       if (!GTK_WIDGET_TOPLEVEL (widget))
 	gtk_widget_queue_resize (widget);
       g_signal_emit (widget, widget_signals[SHOW], 0);
       g_object_notify (G_OBJECT (widget), "visible");
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
     }
 }
 
@@ -2289,7 +2288,7 @@ gtk_widget_hide (GtkWidget *widget)
     {
       GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
       
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       if (toplevel != widget && GTK_WIDGET_TOPLEVEL (toplevel))
 	_gtk_window_unset_focus_and_default (GTK_WINDOW (toplevel), widget);
 
@@ -2297,7 +2296,7 @@ gtk_widget_hide (GtkWidget *widget)
       if (!GTK_WIDGET_TOPLEVEL (widget))
 	gtk_widget_queue_resize (widget);
       g_object_notify (G_OBJECT (widget), "visible");
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
     }
 }
 
@@ -2536,10 +2535,10 @@ gtk_widget_unrealize (GtkWidget *widget)
 
   if (GTK_WIDGET_REALIZED (widget))
     {
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       g_signal_emit (widget, widget_signals[UNREALIZE], 0);
       GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED | GTK_MAPPED);
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
     }
 }
 
@@ -3418,7 +3417,7 @@ gtk_widget_add_accelerator (GtkWidget   
 
   closure = widget_new_accel_closure (widget, query.signal_id);
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
 
   /* install the accelerator. since we don't map this onto an accel_path,
    * the accelerator will automatically be locked.
@@ -3431,7 +3430,7 @@ gtk_widget_add_accelerator (GtkWidget   
 
   g_signal_emit (widget, widget_signals[ACCEL_CLOSURES_CHANGED], 0);
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -3524,7 +3523,7 @@ destroy_accel_path (gpointer data)
   gtk_accel_group_disconnect (apath->accel_group, apath->closure);
 
   /* closures_destroy takes care of unrefing the closure */
-  g_object_unref (apath->accel_group);
+  g_object_unref_and_context (apath->accel_group);
   
   g_slice_free (AccelPath, apath);
 }
@@ -3571,7 +3570,7 @@ gtk_widget_set_accel_path (GtkWidget    
 
       gtk_accel_map_add_entry (accel_path, 0, 0);
       apath = g_slice_new (AccelPath);
-      apath->accel_group = g_object_ref (accel_group);
+      apath->accel_group = g_object_ref_with_context (accel_group, &apath->accel_group);
       apath->path_quark = g_quark_from_string (accel_path);
       apath->closure = widget_new_accel_closure (widget, GTK_WIDGET_GET_CLASS (widget)->activate_signal);
     }
@@ -3799,7 +3798,7 @@ gtk_widget_event_internal (GtkWidget *wi
   if (!event_window_is_still_viewable (event))
     return TRUE;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
 
   g_signal_emit (widget, widget_signals[EVENT], 0, event, &return_val);
   return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
@@ -3905,7 +3904,7 @@ gtk_widget_event_internal (GtkWidget *wi
   else
     return_val = TRUE;
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 
   return return_val;
 }
@@ -4035,10 +4034,10 @@ gtk_widget_reparent_fixup_child (GtkWidg
   if (GTK_WIDGET_NO_WINDOW (widget))
     {
       if (widget->window)
-	g_object_unref (widget->window);
+	g_object_unref_and_context (widget->window);
       widget->window = (GdkWindow*) client_data;
       if (widget->window)
-	g_object_ref (widget->window);
+	g_object_ref_and_context (widget->window);
 
       if (GTK_IS_CONTAINER (widget))
         gtk_container_forall (GTK_CONTAINER (widget),
@@ -4073,10 +4072,10 @@ gtk_widget_reparent (GtkWidget *widget,
       if (GTK_WIDGET_REALIZED (widget) && GTK_WIDGET_REALIZED (new_parent))
 	GTK_PRIVATE_SET_FLAG (widget, GTK_IN_REPARENT);
       
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       gtk_container_remove (GTK_CONTAINER (widget->parent), widget);
       gtk_container_add (GTK_CONTAINER (new_parent), widget);
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
       
       if (GTK_WIDGET_IN_REPARENT (widget))
 	{
@@ -4202,10 +4201,10 @@ gtk_widget_grab_focus (GtkWidget *widget
   if (!GTK_WIDGET_IS_SENSITIVE (widget))
     return;
   
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   g_signal_emit (widget, widget_signals[GRAB_FOCUS], 0);
   g_object_notify (G_OBJECT (widget), "has-focus");
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 static void
@@ -4673,7 +4672,7 @@ gtk_widget_set_parent (GtkWidget *widget
   /* keep this function in sync with gtk_menu_attach_to_widget()
    */
 
-  g_object_ref_sink (widget);
+  g_object_ref_sink_with_context (widget, &widget->parent);
   widget->parent = parent;
 
   if (GTK_WIDGET_STATE (parent) != GTK_STATE_NORMAL)
@@ -5107,7 +5106,7 @@ gtk_widget_set_style_internal (GtkWidget
 			       GtkStyle	 *style,
 			       gboolean   initial_emission)
 {
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   g_object_freeze_notify (G_OBJECT (widget));
 
   if (widget->style != style)
@@ -5122,7 +5121,7 @@ gtk_widget_set_style_internal (GtkWidget
       
       previous_style = widget->style;
       widget->style = style;
-      g_object_ref (widget->style);
+      g_object_ref_and_context (widget->style);
       
       if (GTK_WIDGET_REALIZED (widget))
 	widget->style = gtk_style_attach (widget->style, widget->window);
@@ -5132,7 +5131,7 @@ gtk_widget_set_style_internal (GtkWidget
 		     widget_signals[STYLE_SET],
 		     0,
 		     initial_emission ? NULL : previous_style);
-      g_object_unref (previous_style);
+      g_object_unref_with_context (previous_style, &widget->style);
 
       if (GTK_WIDGET_ANCHORED (widget) && !initial_emission)
 	gtk_widget_queue_resize (widget);
@@ -5147,7 +5146,7 @@ gtk_widget_set_style_internal (GtkWidget
     }
   g_object_notify (G_OBJECT (widget), "style");
   g_object_thaw_notify (G_OBJECT (widget));
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 typedef struct {
@@ -5186,7 +5185,7 @@ gtk_widget_propagate_hierarchy_changed_r
 
   if (GTK_WIDGET_ANCHORED (widget) != new_anchored)
     {
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       
       if (new_anchored)
 	GTK_PRIVATE_SET_FLAG (widget, GTK_ANCHORED);
@@ -5201,7 +5200,7 @@ gtk_widget_propagate_hierarchy_changed_r
 			      gtk_widget_propagate_hierarchy_changed_recurse,
 			      client_data);
       
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
     }
 }
 
@@ -5230,16 +5229,16 @@ _gtk_widget_propagate_hierarchy_changed 
     info.new_screen = NULL;
 
   if (info.previous_screen)
-    g_object_ref (info.previous_screen);
+    g_object_ref_and_context (info.previous_screen);
   if (previous_toplevel)
-    g_object_ref (previous_toplevel);
+    g_object_ref_and_context (previous_toplevel);
 
   gtk_widget_propagate_hierarchy_changed_recurse (widget, &info);
 
   if (previous_toplevel)
-    g_object_unref (previous_toplevel);
+    g_object_unref_and_context (previous_toplevel);
   if (info.previous_screen)
-    g_object_unref (info.previous_screen);
+    g_object_unref_and_context (info.previous_screen);
 }
 
 static void
@@ -5248,7 +5247,7 @@ gtk_widget_propagate_screen_changed_recu
 {
   HierarchyChangedInfo *info = client_data;
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   
   do_screen_change (widget, info->previous_screen, info->new_screen);
   
@@ -5257,7 +5256,7 @@ gtk_widget_propagate_screen_changed_recu
 			  gtk_widget_propagate_screen_changed_recurse,
 			  client_data);
   
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -5323,12 +5322,12 @@ _gtk_widget_propagate_screen_changed (Gt
   info.new_screen = gtk_widget_get_screen (widget);
 
   if (previous_screen)
-    g_object_ref (previous_screen);
+    g_object_ref_and_context (previous_screen);
 
   gtk_widget_propagate_screen_changed_recurse (widget, &info);
 
   if (previous_screen)
-    g_object_unref (previous_screen);
+    g_object_unref_and_context (previous_screen);
 }
 
 static void
@@ -5362,12 +5361,12 @@ gtk_widget_reset_rc_styles (GtkWidget *w
 GtkStyle*
 gtk_widget_get_default_style (void)
 {
+  static GtkStyle *gtk_default_style = NULL;
   if (!gtk_default_style)
     {
       gtk_default_style = gtk_style_new ();
-      g_object_ref (gtk_default_style);
     }
-  
+
   return gtk_default_style;
 }
 
@@ -5593,9 +5592,9 @@ gtk_widget_set_parent_window   (GtkWidge
       g_object_set_qdata (G_OBJECT (widget), quark_parent_window, 
 			  parent_window);
       if (old_parent_window)
-	g_object_unref (old_parent_window);
+	g_object_unref_with_context (old_parent_window, widget);
       if (parent_window)
-	g_object_ref (parent_window);
+	g_object_ref_with_context (parent_window, widget);
     }
 }
 
@@ -5630,7 +5629,7 @@ gtk_widget_set_child_visible (GtkWidget 
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (!GTK_WIDGET_TOPLEVEL (widget));
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
 
   if (is_visible)
     GTK_PRIVATE_SET_FLAG (widget, GTK_CHILD_VISIBLE);
@@ -5655,7 +5654,7 @@ gtk_widget_set_child_visible (GtkWidget 
 	gtk_widget_unmap (widget);
     }
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -6423,6 +6422,11 @@ gtk_widget_get_settings (GtkWidget *widg
  * for the widget).
  * 
  **/
+static void
+widget_unset_colormap (gpointer ptr)
+{
+   g_object_unref_with_context (ptr, widget_unset_colormap);
+}
 void
 gtk_widget_set_colormap (GtkWidget   *widget,
                          GdkColormap *colormap)
@@ -6431,12 +6435,10 @@ gtk_widget_set_colormap (GtkWidget   *wi
   g_return_if_fail (!GTK_WIDGET_REALIZED (widget));
   g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
-  g_object_ref (colormap);
-  
   g_object_set_qdata_full (G_OBJECT (widget), 
 			   quark_colormap,
-			   colormap,
-			   g_object_unref);
+			   g_object_ref_with_context (colormap, widget_unset_colormap),
+			   widget_unset_colormap);
 }
 
 /**
@@ -6794,7 +6796,7 @@ gtk_widget_set_default_direction_recurse
 {
   GtkTextDirection old_dir = GPOINTER_TO_UINT (data);
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   
   if (!GTK_WIDGET_DIRECTION_SET (widget))
     gtk_widget_emit_direction_changed (widget, old_dir);
@@ -6804,7 +6806,13 @@ gtk_widget_set_default_direction_recurse
 			  gtk_widget_set_default_direction_recurse,
 			  data);
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
+}
+
+static void
+ref_with_context (gpointer obj, gpointer ctx)
+{
+   g_object_ref_with_context (obj, ctx);
 }
 
 /**
@@ -6828,13 +6836,13 @@ gtk_widget_set_default_direction (GtkTex
       gtk_default_direction = dir;
 
       tmp_list = toplevels = gtk_window_list_toplevels ();
-      g_list_foreach (toplevels, (GFunc)g_object_ref, NULL);
+      g_list_foreach (toplevels, ref_with_context, gtk_widget_set_default_direction);
       
       while (tmp_list)
 	{
 	  gtk_widget_set_default_direction_recurse (tmp_list->data,
 						    GUINT_TO_POINTER (old_dir));
-	  g_object_unref (tmp_list->data);
+	  g_object_unref_with_context (tmp_list->data, gtk_widget_set_default_direction);
 	  tmp_list = tmp_list->next;
 	}
 
@@ -6890,7 +6898,7 @@ gtk_widget_real_destroy (GtkObject *obje
   
   g_object_unref (widget->style);
   widget->style = gtk_widget_get_default_style ();
-  g_object_ref (widget->style);
+  g_object_ref_and_context (widget->style);
 
   GTK_OBJECT_CLASS (gtk_widget_parent_class)->destroy (object);
 }
@@ -6906,7 +6914,7 @@ gtk_widget_finalize (GObject *object)
   
   gtk_grab_remove (widget);
 
-  g_object_unref (widget->style);
+  g_object_unref_and_context (widget->style);
   widget->style = NULL;
 
   if (widget->name)
@@ -6990,7 +6998,7 @@ gtk_widget_real_realize (GtkWidget *widg
   if (widget->parent)
     {
       widget->window = gtk_widget_get_parent_window (widget);
-      g_object_ref (widget->window);
+      g_object_ref_and_context (widget->window);
     }
   widget->style = gtk_style_attach (widget->style, widget->window);
 }
@@ -7030,13 +7038,10 @@ gtk_widget_real_unrealize (GtkWidget *wi
     {
       gdk_window_set_user_data (widget->window, NULL);
       gdk_window_destroy (widget->window);
-      widget->window = NULL;
     }
   else
-    {
-      g_object_unref (widget->window);
-      widget->window = NULL;
-    }
+    g_object_unref_and_context (widget->window);
+  widget->window = NULL;
 
   gtk_selection_remove_all (widget);
   
@@ -7121,7 +7126,7 @@ gtk_widget_propagate_state (GtkWidget   
 
   if (old_state != GTK_WIDGET_STATE (widget))
     {
-      g_object_ref (widget);
+      g_object_ref_and_context (widget);
       
       if (!GTK_WIDGET_IS_SENSITIVE (widget) && GTK_WIDGET_HAS_GRAB (widget))
 	gtk_grab_remove (widget);
@@ -7141,7 +7146,7 @@ gtk_widget_propagate_state (GtkWidget   
 				   (GtkCallback) gtk_widget_propagate_state,
 				   data);
 	}
-      g_object_unref (widget);
+      g_object_unref_and_context (widget);
     }
 }
 
@@ -7195,7 +7200,7 @@ gtk_widget_aux_info_destroy (GtkWidgetAu
 static void
 gtk_widget_shape_info_destroy (GtkWidgetShapeInfo *info)
 {
-  g_object_unref (info->shape_mask);
+  g_object_unref_and_context (info->shape_mask);
   g_slice_free (GtkWidgetShapeInfo, info);
 }
 
@@ -7239,7 +7244,7 @@ gtk_widget_shape_combine_mask (GtkWidget
       g_object_set_qdata_full (G_OBJECT (widget), quark_shape_info, shape_info,
 			       (GDestroyNotify) gtk_widget_shape_info_destroy);
       
-      shape_info->shape_mask = g_object_ref (shape_mask);
+      shape_info->shape_mask = g_object_ref_and_context (shape_mask);
       shape_info->offset_x = offset_x;
       shape_info->offset_y = offset_y;
       
@@ -7291,7 +7296,7 @@ gtk_widget_input_shape_combine_mask (Gtk
 			       shape_info,
 			       (GDestroyNotify) gtk_widget_shape_info_destroy);
       
-      shape_info->shape_mask = g_object_ref (shape_mask);
+      shape_info->shape_mask = g_object_ref_and_context (shape_mask);
       shape_info->offset_x = offset_x;
       shape_info->offset_y = offset_y;
       
@@ -7496,7 +7501,7 @@ gtk_widget_style_get_property (GtkWidget
   g_return_if_fail (property_name != NULL);
   g_return_if_fail (G_IS_VALUE (value));
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   pspec = g_param_spec_pool_lookup (style_property_spec_pool,
 				    property_name,
 				    G_OBJECT_TYPE (widget),
@@ -7527,7 +7532,7 @@ gtk_widget_style_get_property (GtkWidget
 		   g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
 		   G_VALUE_TYPE_NAME (value));
     }
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
@@ -7550,7 +7555,7 @@ gtk_widget_style_get_valist (GtkWidget  
 
   g_return_if_fail (GTK_IS_WIDGET (widget));
 
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
 
   name = first_property_name;
   while (name)
@@ -7588,7 +7593,7 @@ gtk_widget_style_get_valist (GtkWidget  
       name = va_arg (var_args, gchar*);
     }
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
 }
 
 /**
Index: gtk/gtkwindow-decorate.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow-decorate.c,v
retrieving revision 1.17
diff -u -p -r1.17 gtkwindow-decorate.c
--- gtk/gtkwindow-decorate.c	1 Sep 2005 05:11:43 -0000	1.17
+++ gtk/gtkwindow-decorate.c	19 Jul 2006 22:44:17 -0000
@@ -517,7 +517,7 @@ gtk_decorated_window_button_release (Gtk
 	  GdkEvent *event = gdk_event_new (GDK_DELETE);
 
 	  event->any.type = GDK_DELETE;
-	  event->any.window = g_object_ref (widget->window);
+	  event->any.window = g_object_ref_with_context (widget->window, &event->any.window);
 	  event->any.send_event = TRUE;
 
 	  gtk_main_do_event (event);
Index: gtk/gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.325
diff -u -p -r1.325 gtkwindow.c
--- gtk/gtkwindow.c	5 Jul 2006 16:22:50 -0000	1.325
+++ gtk/gtkwindow.c	19 Jul 2006 22:44:25 -0000
@@ -804,7 +804,7 @@ gtk_window_init (GtkWindow *window)
   window->gravity = GDK_GRAVITY_NORTH_WEST;
   window->decorated = TRUE;
   window->mnemonic_modifier = GDK_MOD1_MASK;
-  window->screen = gdk_screen_get_default ();
+  window->screen = g_object_ref_with_context (gdk_screen_get_default (), &window->screen);
 
   priv->accept_focus = TRUE;
   priv->focus_on_map = TRUE;
@@ -815,7 +815,7 @@ gtk_window_init (GtkWindow *window)
   if (colormap)
     gtk_widget_set_colormap (GTK_WIDGET (window), colormap);
   
-  g_object_ref_sink (window);
+  g_object_ref_sink_with_context (window, window);
   window->has_user_ref_count = TRUE;
   toplevel_list = g_slist_prepend (toplevel_list, window);
 
@@ -1302,7 +1302,7 @@ gtk_window_set_default (GtkWindow *windo
       GtkWidget *old_default_widget = NULL;
       
       if (default_widget)
-	g_object_ref (default_widget);
+	g_object_ref_with_context (default_widget, &window->default_widget);
       
       if (window->default_widget)
 	{
@@ -1325,12 +1325,14 @@ gtk_window_set_default (GtkWindow *windo
 	}
 
       if (old_default_widget)
-	g_object_notify (G_OBJECT (old_default_widget), "has-default");
+	{
+	  g_object_notify (G_OBJECT (old_default_widget), "has-default");
+	  g_object_unref_with_context (old_default_widget, &window->default_widget);
+	}
       
       if (default_widget)
 	{
 	  g_object_notify (G_OBJECT (default_widget), "has-default");
-	  g_object_unref (default_widget);
 	}
     }
 }
@@ -3988,6 +3990,7 @@ gtk_window_finalize (GObject *object)
     {
       g_signal_handlers_disconnect_by_func (window->screen,
 					    gtk_window_on_composited_changed, window);
+      g_object_unref_and_context (window->screen);
     }
       
   G_OBJECT_CLASS (gtk_window_parent_class)->finalize (object);
@@ -4500,8 +4503,8 @@ gtk_window_event (GtkWidget *widget, Gdk
 	}
       else
 	{
-	  g_object_unref (event->any.window);
-	  event->any.window = g_object_ref (widget->window);
+	  g_object_unref_and_context (event->any.window);
+	  event->any.window = g_object_ref_with_context (widget->window, &event->any.window);
 	}
     }
 
@@ -4659,7 +4662,7 @@ gtk_window_propagate_key_event (GtkWindo
   widget = GTK_WIDGET (window);
   focus = window->focus_widget;
   if (focus)
-    g_object_ref (focus);
+    g_object_ref_and_context (focus);
   
   while (!handled &&
          focus && focus != widget &&
@@ -4672,15 +4675,15 @@ gtk_window_propagate_key_event (GtkWindo
       
       parent = focus->parent;
       if (parent)
-        g_object_ref (parent);
+        g_object_ref_with_context (parent, &focus);
       
-      g_object_unref (focus);
+      g_object_unref_and_context (focus);
       
       focus = parent;
     }
   
   if (focus)
-    g_object_unref (focus);
+    g_object_unref_and_context (focus);
 
   return handled;
 }
@@ -4767,7 +4770,7 @@ do_focus_change (GtkWidget *widget,
 {
   GdkEvent *fevent = gdk_event_new (GDK_FOCUS_CHANGE);
   
-  g_object_ref (widget);
+  g_object_ref_and_context (widget);
   
   if (in)
     GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
@@ -4777,14 +4780,14 @@ do_focus_change (GtkWidget *widget,
   fevent->focus_change.type = GDK_FOCUS_CHANGE;
   fevent->focus_change.window = widget->window;
   if (widget->window)
-    g_object_ref (widget->window);
+    g_object_ref_with_context (widget->window, &fevent->focus_change.window);
   fevent->focus_change.in = in;
   
   gtk_widget_event (widget, fevent);
   
   g_object_notify (G_OBJECT (widget), "has-focus");
 
-  g_object_unref (widget);
+  g_object_unref_and_context (widget);
   gdk_event_free (fevent);
 }
 
@@ -4953,13 +4956,13 @@ gtk_window_real_set_focus (GtkWindow *wi
 
   if (old_focus)
     {
-      g_object_ref (old_focus);
+      g_object_ref_and_context (old_focus);
       g_object_freeze_notify (G_OBJECT (old_focus));
       old_focus_had_default = GTK_WIDGET_HAS_DEFAULT (old_focus);
     }
   if (focus)
     {
-      g_object_ref (focus);
+      g_object_ref_and_context (focus);
       g_object_freeze_notify (G_OBJECT (focus));
       focus_had_default = GTK_WIDGET_HAS_DEFAULT (focus);
     }
@@ -5026,7 +5029,7 @@ gtk_window_real_set_focus (GtkWindow *wi
 	gtk_widget_queue_draw (old_focus);
 	
       g_object_thaw_notify (G_OBJECT (old_focus));
-      g_object_unref (old_focus);
+      g_object_unref_and_context (old_focus);
     }
   if (focus)
     {
@@ -5034,7 +5037,7 @@ gtk_window_real_set_focus (GtkWindow *wi
 	gtk_widget_queue_draw (focus);
 
       g_object_thaw_notify (G_OBJECT (focus));
-      g_object_unref (focus);
+      g_object_unref_and_context (focus);
     }
 }
 
@@ -5053,8 +5056,8 @@ _gtk_window_unset_focus_and_default (Gtk
 {
   GtkWidget *child;
 
-  g_object_ref (window);
-  g_object_ref (widget);
+  g_object_ref_and_context (window);
+  g_object_ref_and_context (widget);
       
   if (GTK_CONTAINER (widget->parent)->focus_child == widget)
     {
@@ -5075,8 +5078,8 @@ _gtk_window_unset_focus_and_default (Gtk
   if (child == widget)
     gtk_window_set_default (window, NULL);
   
-  g_object_unref (widget);
-  g_object_unref (window);
+  g_object_unref_and_context (widget);
+  g_object_unref_and_context (window);
 }
 
 /*********************************
@@ -6908,7 +6911,7 @@ gtk_window_set_screen (GtkWindow *window
     gtk_widget_unrealize (widget);
       
   gtk_window_free_key_hash (window);
-  window->screen = screen;
+  window->screen = g_object_ref_with_context (screen, &window->screen);
   gtk_widget_reset_rc_styles (widget);
   if (screen != previous_screen)
     {
@@ -6919,6 +6922,8 @@ gtk_window_set_screen (GtkWindow *window
       
       _gtk_widget_propagate_screen_changed (widget, previous_screen);
       _gtk_widget_propagate_composited_changed (widget);
+
+      g_object_unref_with_context (previous_screen, &window->screen);
     }
   g_object_notify (G_OBJECT (window), "screen");
 
@@ -7067,14 +7072,14 @@ window_group_cleanup_grabs (GtkWindowGro
   while (tmp_list)
     {
       if (gtk_widget_get_toplevel (tmp_list->data) == (GtkWidget*) window)
-	to_remove = g_slist_prepend (to_remove, g_object_ref (tmp_list->data));
+	to_remove = g_slist_prepend (to_remove, g_object_ref_with_context (tmp_list->data, &to_remove));
       tmp_list = tmp_list->next;
     }
 
   while (to_remove)
     {
       gtk_grab_remove (to_remove->data);
-      g_object_unref (to_remove->data);
+      g_object_unref_with_context (to_remove->data, &to_remove);
       to_remove = g_slist_delete_link (to_remove, to_remove);
     }
 }
@@ -7095,8 +7100,8 @@ gtk_window_group_add_window (GtkWindowGr
 
   if (window->group != window_group)
     {
-      g_object_ref (window);
-      g_object_ref (window_group);
+      g_object_ref_and_context (window);
+      g_object_ref_with_context (window_group, &window->group);
       
       if (window->group)
 	gtk_window_group_remove_window (window->group, window);
@@ -7105,7 +7110,7 @@ gtk_window_group_add_window (GtkWindowGr
 
       window->group = window_group;
 
-      g_object_unref (window);
+      g_object_unref_and_context (window);
     }
 }
 
@@ -7124,13 +7129,13 @@ gtk_window_group_remove_window (GtkWindo
   g_return_if_fail (GTK_IS_WIDGET (window));
   g_return_if_fail (window->group == window_group);
 
-  g_object_ref (window);
+  g_object_ref_and_context (window);
 
   window_group_cleanup_grabs (window_group, window);
   window->group = NULL;
   
-  g_object_unref (window_group);
-  g_object_unref (window);
+  g_object_unref_with_context (window_group, &window->group);
+  g_object_unref_and_context (window);
 }
 
 /**
@@ -7638,12 +7643,9 @@ gtk_window_get_key_hash (GtkWindow *wind
 static void
 gtk_window_free_key_hash (GtkWindow *window)
 {
-  GtkKeyHash *key_hash = g_object_get_qdata (G_OBJECT (window), quark_gtk_window_key_hash);
+  GtkKeyHash *key_hash = g_object_steal_qdata (G_OBJECT (window), quark_gtk_window_key_hash);
   if (key_hash)
-    {
       _gtk_key_hash_free (key_hash);
-      g_object_set_qdata (G_OBJECT (window), quark_gtk_window_key_hash, NULL);
-    }
 }
 
 /**
Index: tests/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/testgtk.c,v
retrieving revision 1.358
diff -u -p -r1.358 testgtk.c
--- tests/testgtk.c	25 Apr 2006 14:27:32 -0000	1.358
+++ tests/testgtk.c	19 Jul 2006 22:44:39 -0000
@@ -463,12 +463,13 @@ pattern_set_bg (GtkWidget   *widget,
   gdk_window_set_user_data (child, widget);
 }
 
-static void
+static GSList*
 create_pattern (GtkWidget   *widget,
 		GdkWindow   *parent,
 		gint         level,
 		gint         width,
-		gint         height)
+		gint         height,
+		GSList      *windows)
 {
   gint h = 1;
   gint i = 0;
@@ -501,11 +502,13 @@ create_pattern (GtkWidget   *widget,
 	      
 	      child = gdk_window_new (parent, &attributes,
 				      GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP);
+	      windows = g_slist_prepend (windows, child);
 
 	      pattern_set_bg (widget, child, level);
 
 	      if (level < 2)
-		create_pattern (widget, child, level + 1, w, h);
+		windows = create_pattern (widget, child,
+		    level + 1, w, h, windows);
 
 	      gdk_window_show (child);
 	    }
@@ -515,6 +518,8 @@ create_pattern (GtkWidget   *widget,
       i++;
       h *= 2;
     }
+
+  return windows;
 }
 
 #define PATTERN_SIZE (1 << 18)
@@ -548,23 +553,36 @@ pattern_vadj_changed (GtkAdjustment *adj
 }
 
 static void
+pattern_unrealize (GtkWidget *widget,
+		 gpointer   data)
+{
+  g_signal_handlers_disconnect_by_func(widget, pattern_unrealize, data);
+  g_slist_foreach (data, (GFunc) g_object_unref, NULL);
+  g_slist_free (data);
+}
+
+static void
 pattern_realize (GtkWidget *widget,
 		 gpointer   data)
 {
+  GSList *windows;
   pattern_set_bg (widget, widget->window, 0);
-  create_pattern (widget, widget->window, 1, PATTERN_SIZE, PATTERN_SIZE);
+  windows = create_pattern (widget, widget->window,
+      1, PATTERN_SIZE, PATTERN_SIZE, NULL);
+  g_signal_connect_after (widget, "unrealize",
+      G_CALLBACK (pattern_unrealize), windows);
 }
 
 static void 
 create_big_windows (GtkWidget *widget)
 {
   static GtkWidget *window = NULL;
+  static gint current_x;
+  static gint current_y;
   GtkWidget *darea, *table, *scrollbar;
   GtkWidget *eventbox;
   GtkAdjustment *hadj;
   GtkAdjustment *vadj;
-  static gint current_x;
-  static gint current_y;
  
   if (!window)
     {
@@ -638,7 +656,7 @@ create_big_windows (GtkWidget *widget)
   if (!GTK_WIDGET_VISIBLE (window))
     gtk_widget_show_all (window);
   else
-    gtk_widget_hide (window);
+    gtk_widget_destroy (window);
 }
 
 /*
@@ -1206,6 +1224,9 @@ new_pixmap (char      *filename,
 					 filename);
   
   wpixmap = gtk_image_new_from_pixmap (pixmap, mask);
+  g_object_unref (pixmap);
+  if (mask)
+    g_object_unref (mask);
 
   return wpixmap;
 }
@@ -3899,6 +3920,9 @@ create_image (GtkWidget *widget)
       
       pack_image (vbox, "Pixmap",
                   gtk_image_new_from_pixmap (pixmap, mask));
+      g_object_unref (pixmap);
+      if (mask)
+	g_object_unref (mask);
     }
 
   if (!GTK_WIDGET_VISIBLE (window))
@@ -4316,6 +4340,8 @@ create_menus (GtkWidget *widget)
       GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
       gtk_widget_grab_default (button);
       gtk_widget_show (button);
+
+      g_object_unref (accel_group);
     }
 
   if (!GTK_WIDGET_VISIBLE (window))
@@ -4588,8 +4614,10 @@ create_item_factory (GtkWidget *widget)
       gtk_widget_grab_default (button);
 
       gtk_item_factory_delete_item (item_factory, "/Preferences/ShouldNotAppear");
-      
+
       gtk_widget_show_all (window);
+
+      g_object_unref (accel_group);
     }
   else
     gtk_widget_destroy (window);
@@ -4677,6 +4705,8 @@ create_key_lookup (GtkWidget *widget)
       g_signal_connect (window, "response", G_CALLBACK (gtk_object_destroy), NULL);
 
       gtk_widget_show_all (window);
+
+      g_object_unref (accel_group);
     }
   else
     gtk_widget_destroy (window);
@@ -5475,6 +5505,9 @@ create_size_groups (GtkWidget *widget)
     {
       gtk_widget_destroy (window1);
       gtk_widget_destroy (window2);
+
+      g_object_unref (master_size_group);
+      master_size_group = NULL;
     }
   else
     {
@@ -6954,6 +6987,24 @@ static GtkWidget *spin3;
 static gint line_style;
 
 
+static void
+free_ctree_pixmaps (CTreePixmaps *pixmaps)
+{
+  g_object_unref (pixmaps->pixmap1);
+  if (pixmaps->mask1)
+    g_object_unref (pixmaps->mask1);
+
+  g_object_unref (pixmaps->pixmap2);
+  if (pixmaps->mask2)
+    g_object_unref (pixmaps->mask2);
+
+  g_object_unref (pixmaps->pixmap3);
+  if (pixmaps->mask3)
+    g_object_unref (pixmaps->mask3);
+
+  g_slice_free (CTreePixmaps, pixmaps);
+}
+
 static CTreePixmaps *
 get_ctree_pixmaps (GtkCTree *ctree)
 {
@@ -6963,7 +7014,7 @@ get_ctree_pixmaps (GtkCTree *ctree)
   if (!pixmaps)
     {
       GdkColormap *colormap = gdk_screen_get_rgb_colormap (screen);
-      pixmaps = g_new (CTreePixmaps, 1);
+      pixmaps = g_slice_new (CTreePixmaps);
       
       pixmaps->pixmap1 = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap,
 								&pixmaps->mask1, 
@@ -6975,7 +7026,8 @@ get_ctree_pixmaps (GtkCTree *ctree)
 								&pixmaps->mask3,
 								NULL, mini_page_xpm);
       
-      g_object_set_data (G_OBJECT (screen), "ctree-pixmaps", pixmaps);
+      g_object_set_data_full (G_OBJECT (screen), "ctree-pixmaps", pixmaps,
+	  (GDestroyNotify) free_ctree_pixmaps);
     }
 
   return pixmaps;
@@ -7870,10 +7922,14 @@ void create_ctree (GtkWidget *widget)
       rebuild_tree (NULL, ctree);
     }
 
-  if (!GTK_WIDGET_VISIBLE (window))
-    gtk_widget_show_all (window);
+  if (GTK_WIDGET_VISIBLE (window))
+    {
+      g_object_set_data (G_OBJECT (gtk_widget_get_screen (window)),
+	  "ctree-pixmaps", NULL);
+      gtk_widget_destroy (window);
+    }
   else
-    gtk_widget_destroy (window);
+    gtk_widget_show_all (window);
 }
 
 /*
@@ -10297,6 +10353,7 @@ create_wmhints (GtkWidget *widget)
 					     circles_height);
       gdk_window_set_icon (window->window, NULL,
 			   circles, circles);
+      g_object_unref (circles);
       
       gdk_window_set_icon_name (window->window, "WMHints Test Icon");
   
@@ -13436,8 +13493,11 @@ static void
 bench_iteration (GtkWidget *widget, void (* fn) (GtkWidget *widget))
 {
   fn (widget); /* on */
+  gdk_flush ();
   while (g_main_context_iteration (NULL, FALSE));
+
   fn (widget); /* off */
+  gdk_flush ();
   while (g_main_context_iteration (NULL, FALSE));
 }
 
@@ -13483,6 +13543,7 @@ do_bench (char* what, int num)
   int i;
   GtkWidget *widget;
   void (* fn) (GtkWidget *widget);
+
   fn = NULL;
   widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
@@ -13493,8 +13554,6 @@ do_bench (char* what, int num)
 	  if (!buttons[i].do_not_benchmark)
 	    do_real_bench (widget, buttons[i].func, buttons[i].label, num);
 	}
-
-      return;
     }
   else
     {
@@ -13512,6 +13571,8 @@ do_bench (char* what, int num)
       else
 	do_real_bench (widget, fn, buttons[i].label, num);
     }
+
+  gtk_widget_destroy (widget);
 }
 
 void 
@@ -13590,7 +13651,7 @@ main (int argc, char *argv[])
 	usage ();
     }
   if (done_benchmarks)
-    return 0;
+    goto fini;
 
   /* bindings test
    */
@@ -13615,15 +13676,22 @@ main (int argc, char *argv[])
 
   gtk_main ();
 
-  if (1)
+fini:
+  gtk_window_set_default_icon_list (NULL);
+  gtk_icon_factory_remove_default (NULL);
+  gdk_display_close (gdk_display_get_default ());
+
+  do
     {
-      while (g_main_context_pending (NULL))
-	g_main_context_iteration (NULL, FALSE);
-#if 0
-      sleep (1);
-      while (g_main_context_pending (NULL))
-	g_main_context_iteration (NULL, FALSE);
-#endif
+      while (gtk_events_pending ())
+	gtk_main_iteration ();
+
+      gdk_flush ();
+      g_usleep (1000);
+      gdk_flush ();
     }
+  while (gtk_events_pending ());
+
+  g_main_context_unref (g_main_context_default ());
   return 0;
 }
