Re: GObject dispose vs. finalize

Ryan McDougall <NQG24419 nifty com> writes:

> I want to make sure I understand the differences between the two. Is the
> following correct/accurate? What would you add?
> "The dispose method is supposed to release any references to resources
> when the object first knows it will be destroyed. The dispose method may
> be called any number of times, and thus the code therein should be safe
> in that case. The finalize method finishes releasing the remaining
> resources just before the object itself will be freed from memory, and
> therefore it will only be called once. The two step process helps reduce
> cyclic references. Both dispose and finalize must chain up to their
> parent objects by calling their parent's respective methods *after* they
> have disposed or finalized their own members.
Seems OK.

> Knowing which method is the appropriate place to put certain destruction
> code is in general not an easy problem to solve. However, when dealing
> with reference counted libraries (such as GTK+), one should unreference
> all objects in dispose, and free all memory or close file descriptors in
> finalize."
> How does one make sure their code is safe inside dispose? With static
> variables?

Andreas Rottmann         | Rotty ICQ      | 118634484 ICQ | a rottmann gmx at      | GnuPG Key:
Fingerprint              | DFB4 4EB4 78A4 5EEE 6219  F228 F92F CFC5 01FD 5B62

Beware of bugs in the above code; I have only proved it correct,
not tried it.  -- Donald E. Knuth

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