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

Re: Attaching Data to Objects - when is destroy invoked




On Wed, 25 Aug 1999, Kent Schumacher wrote:
> 
> My feeling about how an 'object' should behave is that it should
> call the destroy method of user attached data whenever the object
> is destroyed.
> 
> I could use some educating about the rational behind this behaviour.
> 

The insight you need is that your data is destroyed when an object is
_finalized_, that is, when its reference count reaches 0. Objects start
with a count of 1; if you add them to the container, the container
"assumes" the count and unrefs the object when the container is destroyed.
Destruction renders an object "unusable" but still "safe," when the count
finally reaches 0 then the object is actually freed ("finalized").

My book's sample chapters talk about this some, 
http://pobox.com/~hp/gnome-app-devel.html

Anyway, basically you own the object's initial refcount until you hand it
to a container, so you need to unref the object instead of destroying it.

Havoc




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