On Jul 15, 2009, at 18:50, Thiago Arrais wrote:

> All,
>
>> [Original message to gtk2hs-users]
>>
>> I have been repeatedly beaten by accelerators in the last two weeks
>> and tried to dig this bug myself with no success. The problem is my
>> accelerators start working but after being used for some time they
>> just wear off and stop working
>
> I've finally managed to isolate and fix this bug after some more
> debugging. It was an issue with glib's reference counting. The action
> group's reference counter was dropping to zero and it was getting
> finalized somehow after some number of action activations. When it was
> finalized it took the actions and accelerator with it, thus everything
> stopped working.

Well done for tracking this down!

> I changed the action group creation code to use makeNewGObject instead
> of constructNewGObject, since it includes reference incrementing, and
> everything now works. There's patch available at my personal repo at
> http://thiagoarrais.com/repos/gtk2hs-upstream/. This patch fixes this
> issue, but I'm not sure it is the right way to do it. I may have
> introduced a memory leak without noticing. Maybe instead of
> incrementing the counter here we should stop decrementing it somewhere
> else...

The reference counter is (and was in your case) decremented by  
Haskell's garbage collector.
So it's definitely the increment that's wrong somewhere.

As far as I understand the documentation (and it's not all that clear):

- If something derives from GObject then on construction it has a ref  
count of one. In this case constructGObject is correct.
- If you extract an exisiting GObject from some structure of Gtk,  
then you need to call makeGObject on it which increases the ref count  
(so that it is at least two)

As soon if something derives from GInitiallyUnowned (subclass of  
GObject) there's a floating reference to get rid of:

- On construction, use constructObject which refSink's the object,  
meaning it turns the floating reference into a real reference so that  
the ref count is one, just as it is for GObjects.

- On extraction from some existing structure, use makeObject which  
increases the ref count (so that it is at least two).

I think we didn't quite understand the first case. GObjects also seem  
to have a floating reference (although the documentation says they  
don't:

http://library.gnome.org/devel/gobject/unstable/gobject-The-Base- 
Object-Type.html#gobject-The-Base-Object-Type.description

). Could you revert your changes to accelGroupNew and change, in  
glib/.../GObject.chs.pp

constructNewGObject constr generator = do
   objPtr <- generator
   obj <- newForeignPtr objPtr objectUnref
   return $! constr obj

to

constructNewGObject constr generator = do
   objPtr <- generator
   objectRefSink objPtr
   obj <- newForeignPtr objPtr objectUnref
   return $! constr obj

If this fixes your problem, the I think this should go into Gtk2Hs as  
this might fix other problems not found so far.

Cheers,
Axel.




------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Gtk2hs-devel mailing list
Gtk2hs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gtk2hs-devel

Reply via email to