gtk_object_unref



Hello everyone,

I'm trying to use the gtk_object_ref and gtk_object_unref function.

I have objects which are referencing shared points.
Let say an object called A reference the point P. If P was not already
created, I'm creating it.
Then I add another object B which reference P also. As P is already created,
I using gtk_object_ref on P.

If I remove B then I unref P and if I remove A, I again unref P but I want
him to be destroy. It is working but I get an unnicely warning message in my
xterm saying that :
Gtk-CRITICAL **: file gtkobject.c: line 1179 (gtk_object_unref): assertion
`object->ref_count > 0' failed.


So I went looking at the source code of gtk_object_unref and I found this
piece code :
void gtk_object_unref (GtkObject *object)
{
  g_return_if_fail (object != NULL);
  g_return_if_fail (GTK_IS_OBJECT (object));
  g_return_if_fail (object->ref_count > 0);

  if (object->ref_count == 1)
    {
      gtk_object_destroy (object);

      g_return_if_fail (object->ref_count > 0);
    }

  object->ref_count -= 1;

  if (object->ref_count == 0)
    {
      object->klass->finalize (object);
    }
}

So when unref is called and there was only one last reference on the object,
destroy is called. As destroy doesn't decremente ref_count it should be
fine, but it seems not to work as I've done a printf of object->ref_count
before calling unref and I got 1 before calling gtk_object_unref and 0
after...

(I've read some older threads about it - like the one about the container -
but in my case my objects and points are drawings on a gtk-canvas and I want
to ref and unref some of the GtkCanvasItem that are shared...)


I hope I've been clear enough, if you need more explanation, tell me what
you didn't understand and I will try to say it differently.
Thanks a lot in advance,


Best regards,
---
Jean-Christophe Berthon

Cap Gemini -- Ernst & Young
France
Skill Integration System -- Image Quality
Email: Jean-Christophe Berthon cgey com
Tel: (+33) 561 31 6639







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