Re: GSource object lifetime
- From: Tadej BorovÅak <tadeboro gmail com>
- To: Thomas Stover <thomas wsinnovations com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GSource object lifetime
- Date: Tue, 3 May 2011 22:50:38 +0200
That did help (I think I still have an unrelated leak). I think a few
things could be made more clear in the docs (I'm not 100% sure I'm correct
I must agree with you here. Docs are a bit scarce on this topic. But ...
-A newly created source (from g_idle_source_new() ) has a reference count
of 1 not 0.
-g_source_attach() increases the reference count by 1
-returning FALSE in a source callback function detaches the source from
the source's attached main context, and decreases the reference count by 1
-Once a source has been detached by source callback function returning
FALSE, it can not be reattached g_source_attach(). An assertion error is
thrown. You can however, decrease the source's reference count down to 0 so
it will free itself, then create a fresh source.
You got it exactly right. I would only add that you decrease reference
count right after attaching it to context (like Colomban already
suggested). This way memory used by source will be freed when detached
All that being said, maybe you could "cook up" a patch for API docs
with this info? I'm sure people would find it useful.
tadeboro gmail com
tadej borovsak gmail com
] [Thread Prev