[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: GIOChannel reference counting
- From: Axel Simon <A Simon kent ac uk>
- To: Richard Warren <rew primagraphics co uk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GIOChannel reference counting
- Date: Mon, 12 Dec 2005 11:09:29 +0000
On Mon, 2005-12-12 at 10:56 +0000, Richard Warren wrote:
> Dear all,
>
> I would be grateful if anyone could tell me whether I need to unreference a
> GIOChannel in order to destroy it properly.
>
> Here's what I'm currently doing:
>
> 1. I create a channel with g_io_channel_unix_new() from a socket. The docs
> state that the initial reference count will be 1.
> 2. I then add a watch on it with g_io_add_watch().
> 3. At a later date, I remove the watch with g_source_remove().
> 4. I want to destroy the channel and free all resources, so call
> g_io_channel_shutdown().
>
> However, the docs for the shutdown function state that the channel will not
> be freed until the last reference is dropped using g_io_channel_unref().
> Does this include the initial reference added on creation, or is that
> unreferenced by the shutdown function.
The comment in the shutdown function wants to say that
"g_io_channel_shutdown" doesn't touch the reference counter. Hence you
need to unref the channel manually.
What you can (probably) do is the following:
1. Create the channel.
2. Add the watch. The watch should add a reference to the channel.
3. Call unref on the channel. Now the watch holds the only reference to
the channel.
4. Remove the watch with g_source_remove, this will drop the ref count
to 0 and destroy the channel. The channel will be flushed.
In general, every low-level object that is not a GtkObject or derived
therefrom has a reference count of 1 and hence needs to be unref'd by
whomever called the constructor.
Hope this helps,
Axel.
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]