Page 1 of 1

need help on gtk

Posted: Tue Aug 25, 2015 8:50 am
by peter
Got a memory problem in plain c, gtk code.
And Google does not provide any insight.

In a routine that is called a few times a second I need to draw.
This code is a problem :

Code: Select all

GdkGC *myGC ; 

//this leaks lots of memory here  !!
myGC = gdk_gc_new(parentcontainer->window); 

// if a color changes need to do this but it leaks memory...
grey.red=1000;
grey.green=1000;
grey.blue=10000 * adj;
gdk_colormap_alloc_color (colormap, &grey, TRUE, TRUE); 
The gc and the allocate color needs to be local and the gc needs to be local too (why ?)
I can not find a way to free the allocated gc and color.

I'm grateful for all the help I can get.

Re: need help on gtk

Posted: Wed Aug 26, 2015 4:40 am
by tramp
peter wrote://this leaks lots of memory here !!
myGC = gdk_gc_new(parentcontainer->window);
you should use
g_object_unref(myGC);
https://developer.gnome.org/gdk2/stable ... k-gc-unref
peter wrote:gdk_colormap_alloc_color (colormap, &grey, TRUE, TRUE);
use
gdk_colormap_free_colors(colormap, &grey, 3);
https://developer.gnome.org/gdk2/stable ... ree-colors

Re: need help on gtk

Posted: Wed Aug 26, 2015 8:56 am
by peter
@tramp Thanks man, that is it. :D