I created a simple application that only creates and displays empty 50x50 window, but it already consumes 20MB of memory. I am targeting low-memory devices, so each megabyte really counts. What causes GTK to consume all that memory? Is it possible to reduce memory usage?
Here's the complete source code for the program:
#include <gtk/gtk.h>
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DOCK);
gtk_window_set_default_size(GTK_WINDOW(window), 50, 50);
gtk_window_move(GTK_WINDOW(window), 50, 50);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
Here's what I compile it with:
gcc -std=gnu99 -Wall -o example main.c $(pkg-config --cflags --libs gtk+-3.0)
And here's the resulting memory usage:
$ ps -FC example
UID PID PPID C SZ RSS PSR STIME TTY TIME CMD
platon 4214 11052 7 84812 20996 1 16:13 pts/5 00:00:00 ./example
(ps measures memory usage in KB, so that's 20996KB or ~21MB)
I'm using gtk3 version 3.22.16, on linux 4.11.6, x86_64.
Problem context: target system is relatively low-memory PC (200-400 MB of memory). Application is kiosk-like interface on that PC, with relatively complex GUI structure (many pages and possible interactions). And I would have preferred to avoid re-implementing all the GUI logic manually (on top of lower-level libraries), so I was looking for something higher-level - and it seems there is only GTK and Qt in that space (Qt is usable only from C++, which is a pain).