On 11-Feb-01, 17:47 (CST), Andrae Muys <[EMAIL PROTECTED]> wrote: 
> Calin Vatavu wrote:
> > 
> > Yes, you have to free it (with g_free I believe), but it's better
> > to make it static:
> > ..
> >       static GtkStyle       * style=0;
> > 
> >       if (!style) {style=gtk_style_new();}
> > ..
> > It's faster, but non-reentrant
> > 
> It also does nothing to solve the memory leak :)
> 
> Specifically it isn't the pointer that was leaking, it was the memory
> being pointed at.  The pointer itself is an automatic variable (you've
> moved it to .bss), and as such is allocated on the stack on function
> entry.  It is automatically dealocated when the stack is unrolled on
> return.

No, it's not. That's what "static" means.  The pointer is not
deallocated, and remains valid the next time the function is called.

> You are then allocating a new GtkStyle (ref=1).  

No, because on the second (and subsequent) calls, the "if (!style)"
fails, and gtk_style_new() isn't called. What will happen is the
_set_style() call will decrement the refcount to 1 and then re-increment
it back to 2. (He writes confidently, without actually testing, because
he likes the taste of foot).

Whether it's the best approach is debatable...

Steve


-- 
[EMAIL PROTECTED]

_______________________________________________
Glade-devel maillist  -  [EMAIL PROTECTED]
http://lists.helixcode.com/mailman/listinfo/glade-devel

Reply via email to