Re: [gtk-list] Re: style usage + memory leak



Eric Harlow wrote:

>    /* --- Setup the colors first. --- */
>    style->bg[GTK_STATE_NORMAL] = color;
>    style->fg[GTK_STATE_NORMAL] = color;
> 
>    /* --- Then set the style --- */
>    gtk_widget_set_style (button, style);

Thanks, I also wondered if that was the cause of my
segfaults. There is one more aspect left, which is
the question of memory leaks. What I now do is to
unref the style directly after assigning it as I assume
the widget to ref the style when using it. I don't
get any segfaults with this but could anyone confirm
that this is correct:

  mystyle = gtk_style_copy( gtk_widget_get_style( button ));

  /* change style here */

  gtk_widget_set_style( button, mystyle );

  gtk_style_unref( mystyle );

If I don't unref the style, then the mystyle reference will
get lost and the style cannot get disposed of later on, right?

This leads me to the general question of how to detect
memory leaks in GTK+. I ran dmalloc on the button sample
in GTK+ and it reports 980 memory holes. Do the same with
testgtk and you up at 1100, use testgtk by clicking on
it a few times here and there and the leak climbs up
(although I seem to remember that you get maximum and
then no more - could be wrong). How can I detect memory
holes? I have little understanding of GTK+ built-in
cashing system which probably must create memory holes
in the sense of what dmalloc and friends report. Given
that some of GTK+'s memory leaks have been found only
very recently, I assume that it is impossible to have
any kind of automated detection.

  Thanks,

    Robert

-- 
----------------------------------------------------------------
Robert Roebling   http://wesley.informatik.uni-freiburg.de/~wxxt



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