[cairo] reference counting vs garbage collection
Jonathan Brandmeyer
jbrandmeyer at earthlink.net
Tue Jan 4 20:01:57 PST 2005
On Tue, 2005-01-04 at 22:28 -0500, Carl Worth wrote:
> On Mon, 03 Jan 2005 00:48:11 +0100 (CET), Olivier Andrieu wrote:
> > The problem is that such surfaces use two kinds of resources: the
> > memory (with reference counts) and the FILE*. Garbage collectors
> > automatically manage memory but not other kind of resources.
>
> Thanks for pointing out this distinction in resource classes.
>
> > There could be two functions I think: _destroy (which should rather be
> > named _unref) to manage the memory and _close to indicate that the
> > file resource is not to be used anymore. That's more or less how GTK+
> > work for instance and it works very well with language bindings. When
> > _close() is called, cairo would flush file-based surfaces, and set a
> > flag to indicate nothing should be done on this surface
> > anymore. _unref() decreases the refcount and when it reaches zero, it
> > calls _close() and then frees the memory.
>
> The proposal of _unref()/_close() matches the resource classification
> above. However, it doesn't capture the inherent dependency between the
> two resources. Namely, after finalizing internal state such as FILE*
> with _close() there's nothing useful for the user to do other than
> _unref(). And it doesn't seem useful to expose this inert object state
> to the user, (although the implementation may need it internally).
>
> So, I propose an _unref() function as above, and a _destroy() function
> which is equivalent to the pair of _close() and _unref() as described
> above.
>
> Does that seem workable? Or am I still totally missing some
> GC-language binding issues?
>
> -Carl
There is one significant problem with this solution: It still requires
the client to provide a FILE*, which is overly burdensome in C++.
Please at least consider the proposal that I submitted in the message
titled "C++ bindings".
-Jonathan
More information about the cairo
mailing list