I have some low memory devices (with 4GB RAM), and GTK4 applications consume a lot of memory.
Examples:
-
Even a hello world window may consume more than 100 mb of memory
-
One app was reported to have a 3 fold memory increase after switching from GTK3 to GTK4.
Is there any workaround?
For GTK4 apps, one can set the environment variable GSK_RENDERER=cairo. It makes the apps stop using hardware acceleration (which is usually not available/not very powerful in most low-end devices anyway), but reduces the memory usage from 2-3 fold.
Examples:
-
It was reported that it reduced one application’s memory usage from 100+ MB to 33MB.
-
In my one of the apps I develop, memory usage reduced from 250+ mb to 140 mb after applying this.
How to apply this:
-
If you want this for some particular app, edit its desktop file and replace Exec=env GSK_RENDERER=cairo app_executing_command.
-
For flatpak apps, you can add environment variables with flatseal.
-
Add GSK_RENDERER=cairo to .profile in your home folder.
-
To do it system-wide for all users, add GSK_RENDERER=cairo to a new line in /etc/environment.
Source: https://github.com/gtk-rs/gtk4-rs/issues/1732