Have you tried a minimal example? Unfortunately I don't have access to
gtk-2.0 here, but here is a 1.2 sample that works:

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtkobject.h>
#include <gtk/gtkentry.h>

static void weak_notify_test(gpointer the_data, GtkObject* o);


static void weak_notify_test(gpointer the_data, GtkObject* o){
  int *intarray = (int *) the_data;
  printf("The array: %d %d\n", intarray[0], intarray[1]);

  free(the_data);
}

int main(int argc, char** argv){
   GtkEntry* entry;
   int* intarray;
   gtk_init(&argc, &argv);
   entry = gtk_entry_new ();
   intarray = malloc(2 * sizeof(int));
   intarray[0] = 1;
   intarray[1] = 2;

    gtk_object_weakref (GTK_OBJECT(entry),
                               (GtkDestroyNotify)weak_notify_test,
                               intarray);

    gtk_object_unref(entry);
    return 0;
}



>
> g_object_weak_ref again?

g_object_weak_ref should do. 


>
>
> Thanks anyway! Matias
>
> Nikhil Dinesh escribió:
>>> *- Is there a way to pass a function to free certain struct in a
>>> GtkTreeModel so GTK frees the allocated space when the model's
>>> reference count reach to 0? (without registering it as a G_TYPE).*
>>>       
>>
>> One way is to register the struct as a "weak reference" to the model,
>> using g_object_weak_ref. See:
>>
>> http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html
>>
>>  
>>> *- When reference count starts? I read somewhere that it starts when
>>> you add the widget into a container, is it always this way??? Eg:*
>>>       
>> Reference counting starts when an object is created. In your example:
>>
>>    GtkWidget *entry = gtk_entry_new ();
>>
>> After this statement, there is one reference to the entry. When
>> gtk_container_add is invoked, it takes over ownership of this
>> reference.  That is when the container is destroyed, g_object_unref
>> is invoked on the entry. So one needs to invoke destroy only on the
>> root widget (typically).
>>
>>  
>>> //*No reference counting on GtkEntry*//
>>>     GtkWidget *entry = gtk_entry_new ();
>>> //*Reference counting starts here *//
>>>     gtk_container_add (GTK_CONTAINER (window), entry);/
>>> /* Another doubt: in this case, reference couting starts with 1 or
>>> 2? */
>>> /
>>> -* If i get a string from a GtkTreeModel, it gives me a copy or the
>>> actual pointer to the data?
>>>       
>> If you're using the get_value method on the iterator, the object is
>> "copied" into the GValue supplied. Typically this gives you just a
>> reference, and invoking g_value_unset results in just decrementing
>> the  reference count. But what exactly happens during copying depends
>> on your object. See:
>>
>> http://developer.gnome.org/doc/API/2.0/gobject/gobject-Generic-values.html
>>
>>
>>  
>>> *That's it, thanks in advance. Matias.
>>> _______________________________________________
>>> gtk-app-devel-list mailing list
>>> gtk-app-devel-list@gnome.org
>>> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>>>       
>>
>> _______________________________________________
>> gtk-app-devel-list mailing list
>> gtk-app-devel-list@gnome.org
>> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>>
>>   
>

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to