Re: [gnome-db] 2 issues with GdaConnection



Mark Johnson writes:

Hi!

> This is something I find difficult in glib/gnome programming in general 
> - how to know when something needs to be unref'ed, and when something 
> else might be keeping a reference to your object. 

Think about g_object_new, g_object_unref as of g_new, g_free.
The first ones are more complicated of course.

> For example, nothing 
> in the gda_connection_statement_execute or 
> gda_connection_statement_execute_select documentation indicates that the 
> connection reference count will be incremented.  The GdaDataModel page 
> does not even contain the word connection.

Point is that when object is created its reference count is increased.
If you create object, you must unref it. Code itself might increase
reference count to avoid ugly problems when some other part of code
unrefs object in the middle of execution.
Of course any explicit ref must be followed by unref to avoid memory leaks.

g_object_unref also gives you clear API as there's no need to add
xxx_free or xxx_destroy in API functions.

Piotras


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