GObject dispose vs. finalize
- From: Ryan McDougall <NQG24419 nifty com>
- To: gtk-devel-list gnome org
- Subject: GObject dispose vs. finalize
- Date: Mon, 19 Jul 2004 11:50:44 -0600
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.
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?
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]