Allow caching of GObjects via resurrection
Submitted by Alexander Larsson
I'd like to cache GdkPixbuf for the icon theme handling, and the ideal behaviour I want is:
When requesting an icon the first time, create a new pixbuf and return. While any code refs that pixbuf return the same object for any cache request. After the last user unrefs the pixbuf, keep the pixbuf in the cache for N seconds.
There are to my knowledge only two ways to implement this. Use toggle refs, or object ressurection. Toggle refs are not availible to Gtk+ code as there can only be one user of that and bindings use it with pixbufs. That leaves object ressurection. It is possible for the cache to ressurect the pixbufs in the dispose callback if refcount == 1, but that means we will also run other dispose handlers which among other things result in user data being freed, which we don't want.
What we really want is to have a callback right before the dispose callback in g_object_unref so that we can ressurect the object at the last second without it being disposed. However, this requires some GObject changes.
I have an initial patch that adds the "ressurect" vfunc to GObject which can be used to implement caching as above, and a gdk-pixbuf patch that adds a "ressurect" signal which the cache can connect to and add a ref the object from the cache.