[gtkada] Deallocating memory shared as user data
William C Brennan
brennan at netaxs.com
Mon Feb 18 05:39:12 CET 2002
Folks,
I'm rather a novice GTK+ user, so please bear with a possibly
ignorant question...
I've created and displayed a window widget. I also allocated from the heap a
record which contains references to some of the widgets in the
window. A pointer to this record is passed to several widget
callback routines, as user
data, so when one widgets can share information with one another. To
me, this seems like a typical way in which widgets and the user-data
parameter in their callback routines are designed to interact.
My problem came when the window was closed by the user. At that time, I would
have liked to deallocate the record which is shared among the widgets.
In my code, I attempted to do this by capturing the "destroy" signal
for the window, and then deallocating the shared memory. But this
turned out to be a problem, because after calling this routine, GTK+
continued to call
one of my other callbacks (deselecting a selected item in a list)
with the user data pointer it had saved, but which was now no longer
valid!
"Hmmm", I said, "it seems like I want to deallocate my record later
in GTK+'s sequence of events, after I'm sure it's really done calling
my callbacks". So instead of the "destroy" signal, I tried attaching
my dealloction callback routine to the "destroy-event" event, which I
believed to occur later.
But for some reason, GTK never calls my callback for this event. I
even tried capturing "all" events for my window, and many came
through, but never a destroy-event.
So I must be missing something. When is the appropriate time to
deallocate a pointer to memory shared among widgets, and what is the
mechanism? And why can't I seem to capture a destroy-event?
Thanks for any light shed!
-- Bill
More information about the gtkada
mailing list