need help on gtk

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
peter
Established Member
Posts: 13
Joined: Tue Jul 21, 2015 1:48 pm

need help on gtk

Post 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.
Trying is what I do best.
tramp
Established Member
Posts: 2335
Joined: Mon Jul 01, 2013 8:13 am
Has thanked: 9 times
Been thanked: 454 times

Re: need help on gtk

Post 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
On the road again.
peter
Established Member
Posts: 13
Joined: Tue Jul 21, 2015 1:48 pm

Re: need help on gtk

Post by peter »

@tramp Thanks man, that is it. :D
Trying is what I do best.
Post Reply