Re: should I ref/strdup values in my _set_property() method



Stefan Kost wrote:
[...]
statc void xxx_yyy_set_property(...) {
  ...
  switch(property_id) {
    case OBJECT_PROP:
      if(myobject) g_object_unref(myobject);
      myobject=g_object_ref(g_value_get_object(value));
      break;
    case STRINTG_PROP:
      if(mystring) g_free(mystring);
      mystring=g_value_dup_string(value);
      break;
  }
}

   The GValue containing the string will be destroyed so
it is nescisary to dup the string (get string is a pointer
to the GValue's copy). The GValue probably holds a reference
to the object untill the GValue is destroyed as well, so If you
want a reference, you need to reference it ;-)

Cheers,
                               -Tristan



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