[cairo] reference counting vs garbage collection
Keith Packard
keithp at keithp.com
Wed Jan 5 10:36:28 PST 2005
Around 12 o'clock on Jan 5, Olivier Andrieu wrote:
> ah but why do an _unref in _destroy ? This way the binding has to keep
> track of wether _destroy was called, so that it knows wether to _unref
> or not when the object is collected.
We're trying to preserve the symmetry for non-GC'd languages as well. We
want:
x = _create
...
_destroy (x)
to "just work". Assymmetry in a non-GC'd language invariably leads to
even more memory allocation bugs.
For your case, where you just want _destroy to close the object and not
dereference it, you can use
_ref (x)
_destroy (x)
and then in the finalizer, you can do
_unref (x)
which will have precisely the desired effect.
For my own part, as I want to know when I can finalize both the surface
and any associated FILE object, I will use _destroy from the surface finalizer
right before a call to fclose.
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050105/65d2dae5/attachment.pgp
More information about the cairo
mailing list