[cairo] UserFontFace vs FtFontFace management (cairomm)

Behdad Esfahbod behdad at behdad.org
Thu Dec 4 21:43:43 PST 2008


Jonathon Jongsma wrote:

> Yes, and I do store a *pointer* to the wrapper object in the user-data
> part of the C object, but that does not really help me here since that
> will not keep the wrapper object alive.  It is simply a weak reference
> -- once the wrapper object is destroyed, the pointer will be dangling,
> which causes the memory corruption and crash that Ian reported initially.

I hereby declare the can of worms open :).

> In the current cairomm implementation, the lifetime of the wrapper
> object is managed by the smart pointer that it is created with.  When
> the wrapper object is deleted, the destructor simply calls
> cairo_font_face_destroy() on the wrapped object.  If I were to store an
> owning reference to the wrapper inside of the wrapped C object, the
> wrapper's destructor would never be called, so we'd never _destroy() the
> underlying font face, and it seems that we'd have circular reference
> issues.  Or am I missing something? (quite possible, I admit)

So, this is a very well-known issue.  Managing lifecycle of the proxy objects
is hard.  Really hard.  And impossible to get right with current cairo API.
See "toggle references" in glib.

Is your smart-pointer class able to call you on each ref and unref?  If yes,
there may be hope...

behdad


More information about the cairo mailing list