Index: htmlview.c
===================================================================
RCS file: /cvs/gnome/gtkhtml2/libgtkhtml/view/htmlview.c,v
retrieving revision 1.135
diff -u -r1.135 htmlview.c
--- htmlview.c	15 Apr 2002 15:51:42 -0000	1.135
+++ htmlview.c	24 Apr 2002 18:06:07 -0000
@@ -784,19 +784,45 @@
 	g_object_set_data (G_OBJECT (data), "saved-focus", NULL);
 }
 
+/* We must release all references to other objects here. But be careful as
+   it can be called multiple times. */
 static void
-html_view_finalize (GObject *object)
+html_view_destroy (GtkObject *object)
 {
 	HtmlView *view = HTML_VIEW (object);
+
 	gpointer saved_focus;
 
+	if (view->relayout_timeout_id != 0) {
+		gtk_timeout_remove (view->relayout_timeout_id);
+		view->relayout_timeout_id = 0;
+	}
+
+	if (view->relayout_idle_id != 0) {
+		gtk_idle_remove (view->relayout_idle_id);
+		view->relayout_idle_id = 0;
+	}
+
 	saved_focus = g_object_get_data (G_OBJECT (view), "saved-focus");
 	if (saved_focus) {
 		g_object_weak_unref (G_OBJECT (saved_focus),
 			   	     (GWeakNotify) focus_element_destroyed,
 				     view);
+		g_object_set_data (G_OBJECT (view), "saved-focus", NULL);
+	}
+
+	if (view->document) {
+		g_object_unref (view->document);
+		view->document = NULL;
 	}
-	g_object_unref (view->document);
+
+	GTK_OBJECT_CLASS (parent_class)->destroy (object);
+}
+
+static void
+html_view_finalize (GObject *object)
+{
+	/*HtmlView *view = HTML_VIEW (object);*/
 
 	if (G_OBJECT_CLASS (parent_class)->finalize)
 		(G_OBJECT_CLASS (parent_class)->finalize) (object);
@@ -928,7 +954,7 @@
 	
 	if (view->document != NULL) {
 		html_view_disconnect_document (view, view->document);
-		
+		g_object_unref (view->document);
 		html_view_layout_tree_free (view, view->root);
 	}
 	
@@ -1047,6 +1073,7 @@
 html_view_class_init (HtmlViewClass *klass)
 {
 	GObjectClass *object_class = (GObjectClass *)klass;
+	GtkObjectClass *gtkobject_class = (GtkObjectClass *)klass;
 	GtkWidgetClass *widget_class = (GtkWidgetClass *)klass;
 	GtkContainerClass *container_class = (GtkContainerClass *)klass;
 	GtkBindingSet *binding_set;
@@ -1055,6 +1082,8 @@
 	parent_class = gtk_type_class (GTK_TYPE_LAYOUT);
 
 	object_class->finalize = html_view_finalize;
+
+	gtkobject_class->destroy = html_view_destroy;
 
 	widget_class->focus = html_view_focus;
 	
