Re: [gnome-db] 2 issues with GdaConnection
- From: "Vivien Malerba" <vmalerba gmail com>
- To: "Mark Johnson" <mrj001 shaw ca>
- Cc: gnome-db list <gnome-db-list gnome org>
- Subject: Re: [gnome-db] 2 issues with GdaConnection
- Date: Sun, 23 Mar 2008 14:17:44 +0100
On Sat, Mar 22, 2008 at 10:58 PM, Mark Johnson <mrj001 shaw ca> wrote:
>
> Vivien Malerba wrote:
> >> >
> >> I don't think I have 2 references to the connection. I've attached a
> >> current snapshot of my file to let you see it. It's a work in progress
> >> for a test case for one of my bugs.
> >>
> >
> > The problem comes from the fact that when you call
> > g_object_unref(pConn), there is still an object holding a reference on
> > the pConn object, it is the GdaDataModel returned from the
> > gda_connection_statement_execute_select() function (which you ignore
> > in your example but still exists). Here is attached your example,
> > modified to show the reference count on the pConn object.
> >
> > Cheers,
> >
> > Vivien
> >
> Thanks, that fixed it. The g_object_unref now does close the
> connection, so no unexpected EOF in the PostgreSQL log.
>
> 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. 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.
The idea is that for any function which creates a new object, then you
need to call g_object_unref() on the object, otherwise you must
consider that the returned object is valid only within your function
body (and if you wat to keep it, call g_object_ref() and
g_object_unref() when done with it).
The reason the GdaDataModel keeps a reference on the connection is
that some implementations need to execute some queries when they are
used (like for cursor based access and for the soon-to-come dete model
modification).
Don't hesitate to signal any part of the doc you find misleading or
unclear about that point.
Cheers,
Vivien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]