GtkTextTag still not unreferenced properly


Sorry, this was the message I meant to send.

Havoc, do you remember my previous message about GtkTextTag not being unreferenced properly:

When a GtkTextBuffer is finalized it unreferences its GtkTextTagTable. When the GtkTextTagTable is finalized it calls the following line of code:

gtk_text_tag_table_foreach (table, foreach_unref, NULL);

which unreferences each tag in the table. At the start of this function a tag has a reference count of 2 and after being unreferenced it still has a reference count of 1. When you apply a tag the 'gtk_text_buffer_real_apply_tag()' function gets called. This calls '_gtk_text_btree_tag()" which inturn calls 'gtk_text_btree_get_tag_info()' which increases the reference count of a tag. Searching through the source code I couldn't find any where that the tag gets unreferenced again, except for 'foreach_unref()' in GtkTextTagTable. When I removed the line that increases the reference count I found that GtkTextBuffer, GtkTextTagTable and GtkTextTag still worked properly.

You added the following lines of code to the 'foreach_unref' function in gtktexttagtable.c

tmp = tag->table->buffers;
while (tmp != NULL)
_gtk_text_buffer_notify_will_remove_tag (GTK_TEXT_BUFFER (tmp->data), tag);

tmp = tmp->next;

This should have fixed the problem because _gtk_text_buffer_notify_will_remove_tag() results in gtk_text_btree_remove_tag_info() being called which removes the reference added by gtk_text_btree_get_tag_info(), but it didn't. Going through the code again I noticed that tag->table->buffers is always NULL. Looking at the code from gtk_text_buffer_finalize():

if (buffer->tag_table)
_gtk_text_tag_table_remove_buffer (buffer->tag_table, buffer);
g_object_unref (G_OBJECT (buffer->tag_table));
buffer->tag_table = NULL;

I noticed that the buffer is removed from the tag_table before the tag_table is unreferenced and its finalization code run. When a tag_table has only one buffer tag->table->buffers will always be NULL. I did try to find a way around this problem but couldn't.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]