Re: Accessing a class pointer and class methods



On Sun, 2003-07-13 at 02:15, Gaal Yahas wrote:

What I still want to know is what is the proper way to implement instance
finalization when the object is a GObject and not a GtkObject (GtkObjects
have a "destroy" signal I can conncet to). See the example below: how
do I have unique_thing_finalize called, say, when the thing's refcount
drops to zero?

There are lots of examples in GTK+ of non-GtkObject GObjects, 
look at the handling gtk_list_store_finalize (GObject *object) for a
random example. Note the fact that every finalize function must
chain up to the parent class (and hence the assignment of parent_class
in class_init)

uniqething.c:

     static GHashTable *thing_cache;

     void
     unique_thing_class_init() {
         thing_cache = g_hash_table_new(g_str_hash, g_str_equal);
     }
     void
     unique_thing_class_finalize() {
         g_hash_table_destroy(thing_cache);
     }

Unless you have a dynamically loaded class, there is no reason to
have a class_finalize; class finalizers are only ever called for
dynamically loaded classes. Otherwise, you can just count on the
OS freeing the memory when the program exits in most cases.

Regards,
                                                Owen





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]