Re: [gob-list] signal referencing

From: George <jirka_at_5z.com>
Date: Fri, 10 Jan 2003 09:21:21 -0800

On Wed, Dec 18, 2002 at 04:56:45PM +0100, BRUGUIER Nicolas wrote:
> hi,
>
> First, thank you for this great tools which is gob
>
> I use gob 2.0.4 and i have a some troubles with ref and unref object
> when I use signal,
>
> I have an object who generate signal
>
> class MyObject from G:Object
> {
> private gchar * my_string
> destroy {
> g_print("destroy");
> g_free(my_string);
> };
>
> signal NONE (NONE)
> mysignal(self);
>
> public SELF *
> new(void)
> {
> ...
> selfp->my_string = g_strdup("my_string");
> ...
> }
>
> public void
> action(self)
> {
> ...
> self_mysignal(self);
> ...
> }
> }
>
> and an other who use this:
>
> on_my_signal(MyObject * obj, gpointer user_data)
> {
> my_signal = TRUE;
> }
>
> f()
> {
> MyObject * obj = my_object_new();
>
> my_object_connect__mysignal(obj, on_my_signal, NULL);
> while (!my_signal);
> g_object_unref(obj);
> }
>
> the problem is when the signal is send MyObject is referenced, I saw it
> with my favorite debugger.
>
> Well, when I am in on_my_signal obj->ref_count = 2, OK I add
> g_object_unref in end of on_my_signal but in this case if the signal
> isn't connected the ref count it is always increase. The only solution i
> found is decrease ref_count with g_object_unref after call the signal
> generator.
>
> My question what is the better solution or does have another solutions ?
>
> thank you, in advance, and sorry for my english

Hmmm, the object should be referenced during the signal, the gobject signal
code does that. But it should dereference it after the signal emission is
done. This is because the gobject signal code is referencing the object
and you would otherwise get a crash in case an unref would happen in the
signal handler. I may not be understanding exactly what you mean though ...

Sorry about the late reply ... my inbox was full and I was also mostly on my
vacations ... :)

George

-- 
George <jirka_at_5z.com>
   I know not with what weapons World War III will be fought, but
   World War IV will be fought with sticks and stones.
                       -- Albert Einstein
Received on Fri Jan 10 2003 - 12:21:38 CST

This archive was generated by hypermail 2.2.0 : Sun Apr 17 2011 - 21:05:02 CDT