Re: [Bug 111028] Dealing with reference cycles in GObject



On 2003.04.24 17:44 Havoc Pennington wrote:
> On Thu, Apr 24, 2003 at 04:20:01PM +0100, J. Ali Harlow wrote: 
> > 3. Change gdk_drawable_get_image() to always return a copy of the
> >    image. This is much easier but would reduce efficiency.
> 
> Maybe this is right; otherwise the win32 port has different semantics
> from the X port. Maybe it could return a "shallow copy" of the image
> but it seems like it needs to return a copy...

There's much to be said for this. I haven't actually tested it but
my reading of the current code is that if you use gdk_drawable_get_image()
and then modify the image you'll be changing the pixmap at the same
time. As I say, this makes things much more efficient but should
really be documented if it is to be kept as is.

> However, I'm not sure I understand the refcount cycle that you're
> seeing (i.e. what are all the links in the cycle?)

Maybe that's because it's in my head :-)

The current situation is that the reference counting is simply
wrong which causes the bug I reported. The obvious way to fix
it might be to count all references. However doing so causes
the cycle I describe.

Ie., user calls gdk_pixmap_new() which creates a new GdkPixmap
with a floating reference and then calls
_gdk_win32_setup_pixmap_image() to create a new GdkImage with
a floating reference. _gdk_win32_setup_pixmap_image() creates
a reference to the associated GdkPixmap so does a g_object_ref
followed by a gtk_object_sink. Finally gdk_pixmap_new() does
a g_object_ref/gtk_object_sink on the new GdkImage.

Net result: GdkPixmap returned to the user has reference count
of 1 and the associated GdkImage also has a reference count
of 1. This cycle will prevent the two objects ever being finalized
unless somebody calls g_object_dispose() and the dispose()
function was implemented.

At least, that's how I worked it out in my head. It could be
a load of rubbish. I'm very much a GObject beginner.

Cheers,

-- 
Ali Harlow                              Email: ali avrc city ac uk
Research programmer                     Tel:   (020) 7040 4348
Applied Vision Research Centre          Intl: +44 20 7040 4348
City University                         Fax:   (020) 7040 5515
London                                  Intl: +44 20 7040 5515



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]