Re: Recommended way to cleanup your own gobject types in a desktop app (finalize and/or dispose)
- From: "Tristan Van Berkom" <tvb gnome org>
- To: "Ali Sabil" <ali sabil gmail com>
- Cc: GNOME Desktop Hackers <desktop-devel-list gnome org>
- Subject: Re: Recommended way to cleanup your own gobject types in a desktop app (finalize and/or dispose)
- Date: Sun, 23 Mar 2008 14:06:09 -0300
On Sun, Mar 23, 2008 at 8:00 AM, Ali Sabil <ali sabil gmail com> wrote:
> Hello,
>
> iirc, the GObject documentation states that dispose may be called
> multiple times,
> and the object must still be usable even after dispose is called, so
> freeing memory
> in dispose is wrong, even with locks.
>
> Actually both dispose and finalize are needed if your object hold
> references to other
> objects, and has allocated memory during its init. The dispose will be called as
> many times as necessary to remove the references to other object (and thus break
> possible cycles), and when the object's ref count drop to 0, the
> finalize is called to
> completely free any resource held by the object.
Not to contradict, because you DID just outline the proper way of
freeing up your GObject.
Just pointing out that, in all my personal experience Ive never had
to write a dispose handler to break cyclic references, usually if your
app is well structured and you have a good concept of ownership,
these cyclic situations should remain a myth (in the few cases
I have actually written one, it was only because the source was
open and to set a better example for those who might read the code).
Im sure, deep in the complexities of gtk+, and the possible ways
people can use/misuse it, dispose handlers are needed.
I would actually be interested if someone would show me an example
of where its precisely needed in gtk+ ;-)
Cheers,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]