I created simple GTK program with horizontal box and 2 buttons and it causes huge memory leak.
Here is the code: (you can compile it with gcc main.c `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`)
#include <gtk/gtk.h>
GtkWidget* playorPauseButton;
GtkWidget* stopButton;
int status = 0;
gboolean updateView(gpointer user_data)
{
GtkWidget* image;
if (status == 0)
image=gtk_image_new_from_icon_name ("media-playback-pause",GTK_ICON_SIZE_DND);
else
image=gtk_image_new_from_icon_name ("media-playback-start",GTK_ICON_SIZE_DND);
gtk_button_set_image((GtkButton*)playorPauseButton,image);
return TRUE;
}
int main( int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
GtkWidget* hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,10);
playorPauseButton = gtk_button_new_from_icon_name("media-playback-start",GTK_ICON_SIZE_DND);
gtk_box_pack_start((GtkBox*)hbox,playorPauseButton,0,0,0);
stopButton = gtk_button_new_from_icon_name ("media-playback-stop",GTK_ICON_SIZE_DND);
gtk_widget_set_sensitive(stopButton, FALSE);
gtk_box_pack_start((GtkBox*)hbox,stopButton,0,0,0);
gtk_container_add(GTK_CONTAINER(window), hbox);
gdk_threads_add_timeout (200, updateView, NULL);
gtk_widget_show_all (window);
gtk_main();
return 0;
}
I run this program and checked memory usage using "echo 0 $(awk '/Private/ {print "+", $2}' /proc/PID/smaps) | bc" command from this thread In Linux, how to tell how much memory processes are using?
This is what i get: (memory is in kB and refreshed every 2 second)
10296
10620
12328
12580
12820
13056
13292
13472
13776
13944
14176
14440
14644
14828
15012
I tested this on 2 platform. One with GTK 3.22.3 and Weston, and second with GTK 3.24.2 and Xorg. In second scenario the Xorg process is growing.
The fun part is that when i comment line "gtk_widget_set_sensitive(stopButton, FALSE);" or "gtk_button_set_image (playorPauseButton,image);" there is 0 memory leak. I don't know what is going on, how setting button sensitivity to FALSE can cause so huge memory leak. Please help me understand this.
In case someone is wondering what i am trying to do, i am trying to create control panel to allow start of machine and stopping it, and i want that stop button to be only active when machine is running.