Re: none



On 13 Dec 2000, Havoc Pennington wrote:

> 
> Owen Taylor <otaylor redhat com> writes: 
> > If you want weakrefs, and think object data is inconvenient, then
> > we should spend the two minutes to port:
> > 
> > void gtk_object_weakref	  (GtkObject	    *object,
> > 			   GtkDestroyNotify  notify,
> > 			   gpointer	     data);
> > void gtk_object_weakunref (GtkObject	    *object,
> > 			   GtkDestroyNotify  notify,
> > 			   gpointer	     data);
> > 
> > Though note that the only differences between this and 
> > g_object_set_data_full are a) the presence use of a key, and b) 
> > the order of the arguments.
> > 
> > Clarifying that ::destroy is a "disconnect everything" command
> > rather than notification of the object being freed or going
> > into a "destroyed" state is a major conceptual win for GTK+-2.0.
> > 
> 
> I think most connections to destroy actually are semantically intended
> to happen on "disconnect everything" rather than "object destroyed"
> (since with any kind of garbage collection, even lame gc such as
> refcounting, you should not depend on finalization to happen at any
> special time; what you care about is when the object has been
> explicitly disconnected from the rest of the app - i.e. "destroy" is
> basically "everyone stop using this object so it will get collected" 
> while a weak ref is "tell everyone this object has been collected").
> 
> I'm not sure it's actually interesting to know when an object has been
> garbage collected, and I'm not sure we should be encouraging people to
> put significant code in the finalizer, which is basically what we are
> doing here.

note that weakrefs are invoked once the object is in finalization
stage, the important part here is that at finalization time, the
object has ref_count==0, and object_ref will only work if ref_count>=1
to prevent resurection of dead objects (we don't want zombies, do we? ;)
the inconvenient part here is that when weakrefs are being executed,
certain object memebers may already contain garbage, e.g. from
gtk_label_finalize () { g_free (label->text); }

what we can do here is porting weakrefs like owen said, and execute
them at ref_count-- time, but shortly before ->finalize() is being called.
then weakrefs-notifies are unlikely to access object member garbage,
unless they were setup from a ->finalize() implementation or during
execution of another weakref handler (both being pretty pathetic cases).
they'll never be able to _object_ref objects though.

> 
> Havoc
> 

---
ciaoTJ






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