Re: gobject weak references
- From: Murray Cumming <Murray_Cumming betaresearch de>
- To: Sven Neumann <sven gimp org>
- Cc: gtk-devel-list gnome org
- Subject: Re: gobject weak references
- Date: Tue, 18 Sep 2001 14:59:10 +0200
Sven Neumann wrote:
>
> Hi,
>
> Murray Cumming <Murray_Cumming betaresearch de> writes:
>
> > 1.
> > Is this an accurate description of the new gobject weak references
> > mechanism?:
> > It doesn't actually increase the refcount, so the object might be
> > deleted, but you'll know if it does because it will call your callback
> > function.
>
> sounds good to me.
>
> > 2.
> > The GWeakNofify callback will have this signature:
> > void weaknotify_callback(gpointer data, GObject *where_the_object_was);
> > What is the second argument about?
>
> it is the memory address of the GObject that has been destroyed. You should
> never dereference this pointer since it does not point to a valid GObject
> anymore, but there are cases where you need this pointer. One example is
> that you have a list or hash of GObjects and you want to remove the pointer
> from this list when the GObject gets destroyed. You can very simply
> implement such a weak container by adding a weak reference to the GObject
> whenever you add one to the list and have it removed from the list in the
> weak notifier.
So it should be
void weaknotify_callback(gpointer data, GObject* object)
with warnings about the pointer actually being invalid. At first I
thought that where_the_object_was might be a pointer to a
parent/container object. May I commit that change?
Actually I think that your example is a bit hackish. I would prefer to
use an ID that's passed through data or is stored in the object's
quark-data-thing mechanism. If there's no absolute need to use an
invalid pointer then we shouldn't give people the opportunity.
--
Murray Cumming
www.murrayc.com
murrayc usa net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]