Re: [gnome-db] Little API problems



>  > 
> > GdaColumnIndex:
> > - This is a reference-counted object, but it also has a
> > gda_column_index_free() function. When would/could this be
> > used? I'm pretty sure that it should be removed. It does a
> > g_free() instead of a g_object_unref().
> 
> Done, I've removed it as it was a bad idea to have such a harmfull function!
> 
> 
>  I introduced gda_column_index (originally called
> GdaDataModelColumnIndexAttributes) a couple of months ago.
> Therefore I am just curious about the comment above . Why is (was)
> gda_column_index_free a bad idea while gda_column_free for instance is not?
> Probably not quiet awake here, but just to prevent that I will be making
> similar mistakes in the future.
>  

When you have a GObject derived structure, then you should never call
g_free() on it (unless you want some trouble!), but let the object
free its memory when it's no longer used by its destructor (that is
when its reference count has dropped to 0 which is what the
g_object_unref() method does when you are the only one to hold a
reference on that object).

The gda_column_index_free() function is in fact only to be used by the
destructor of that object, and must not be called from the outside. In
fact no GObject should have a _free() public method.

For that specific part of code, maybe the implementation was wrong in
the first place! It also points that the gda_column_free() function
suffers from the same problem. I'll take care of that.

Thanks for explaining Vivien. Much appreciated!

Bas.



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