Re: [gtk-list] Freeing data connected to a widget via signals...
- From: Thomas Mailund <mailund mail1 stofanet dk>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Freeing data connected to a widget via signals...
- Date: 29 Mar 2000 08:41:16 +0200
>>>>> "M" == Matthew D Allen <s2mdalle@titan.vcu.edu> writes:
M> Let's say I have:
M> typedef struct{
M> char *some_dyn_allocd_mem;
M> char *some_more_mem
M> struct other_structure *ptr; /* Contains further nested pointers */
M> } foobar;
M> and then I create a dynamically allocated foobar (with some
M> subfields that are dynamically allocated) - call it "ptr"
M> then I do:
M> gtk_signal_connect(GTK_OBJECT(my_button), "clicked",
M> GTK_SIGNAL_FUNC(my_button_callback), ptr);
M> How do I know if "ptr" will be correctly freed when the widget
M> gets destroyed?
It won't. GTK wouldn't know how to.
M> How do I attach a "rider" onto the destroyed signal so that I can
M> do a custom free routine on the object data when the widget gets
M> destroyed?
M> I tried gtk_signal_connect_after(GTK_OBJECT(my_button), "destroy",
M> GTK_SIGNAL_FUNC(my_custom_foobar_free) ptr);
M> but it never seems to get called.
hmm, no, there's something about emission of hooks on GTK_DESTROYED
objects, but quite remember what it was. Someone more enlightened
might clear this up.
M> I can't imagine GTK+ knows how to free the fields in my custom
M> data structure, yet at the same time, I don't know how to do it
M> myself.
M> Anybody have an idea how I can do that?
take a look at
guint gtk_signal_connect_full (GtkObject *object,
const gchar *name,
GtkSignalFunc func,
GtkCallbackMarshal marshal,
gpointer data,
GtkDestroyNotify destroy_func,
gint object_signal,
gint after);
where GtkDestroyNotify is
void (*GtkDestroyNotify) (gpointer data);
it's this guy you want to use. The destroy_func is called when the
signal is removed.
/mailund
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]