gnunn1 / tilix

A tiling terminal emulator for Linux using GTK+ 3
https://gnunn1.github.io/tilix-web
Mozilla Public License 2.0
5.42k stars 292 forks source link

Possible memory leak #1558

Closed PD-Extron closed 6 years ago

PD-Extron commented 6 years ago

I'm not sure if this is a known issue, but I've recently noticed very high memory usage in Xorg while using Tilix with several (4-5) sessions and roughly 4-6 tiles per session. I am running Tilix v1.8.5 (via the webupd8 PPA) on an Ubuntu 16.04 VM and also running Tilix v1.7.7 on an Ubuntu 18.04 VM. I am running VMware Workstation 14 on Windows 10.

Reproducing is easy: Create a few sessions with a few tiles in each. You don't really need anything going on in the terminals. Now cycle through each of your sessions one at a time using the sidebar. You'll notice that memory usage (htop) keeps climbing for the Xorg process and the pixelmap ("Pxm mem" column) memory (xrestop) for the Tilix process goes up as well. Even if you close Tilix the memory doesn't seem go down. This will eventually lead to swapping and the swap file will fill up as well which will most likely require a reboot.

The output of "tilix --version" for my two VMs is as follows:

Ubuntu 16.04 VM:

Versions Tilix version: 1.8.5 VTE version: 0.42 GTK Version: 3.18.9

Tilix Special Features Notifications enabled=0 Triggers enabled=0 Badges enabled=0

Ubuntu 18.04 VM:

Versions Tilix version: 1.7.7 VTE version: 0.52 GTK Version: 3.22.30

Tilix Special Features Notifications enabled=0 Triggers enabled=0 Badges enabled=0

Any help with this would be greatly appreciated as I use this for my daily work.

-PD

f2404 commented 6 years ago

I'm seeing a small memory usage increase each time I unfocus/focus the Tilix window. Also, the CPU usage goes to 25% when doing that on my system.

$ tilix -v
Versions
    Tilix version: 1.8.5
    VTE version: 0.55
    GTK Version: 3.22.30

Tilix Special Features
    Notifications enabled=0
    Triggers enabled=0
    Badges enabled=1
PD-Extron commented 6 years ago

UPDATE: It seems that cycling through the sessions using Ctrl-PageUp / Ctrl-PageDown does not have any effect on memory usage. It's only when you manually select the sessions one after another from the side panel is where the memory leaks.

UPDATE 2: Apparently just clicking on the session drop-down list is all you need to do to start creating leaks. Click to open and then close it right away will start leaking memory.

UPDATE 3: If you disable the sidebar by checking Preferences->Appearance->Use tabs instead of sidebar, this problem appears to go away so the issue seems to be sidebar related. I am going to work this way for a few days and see how it goes.

Edited to add UPDATE 2 Edited to add UPDATE 3

FFY00 commented 6 years ago

Probably something is not being properly destructed in cairo.

gnunn1 commented 6 years ago

I can reproduce, after playing around with it I see that the Pixbuf used to draw the thumbnails doesn't get freed. The Image adds a reference to it when constructed and it should get freed when the image gets destroyed and removes the reference. However the SideBarRow (inherits from ListBoxRow) never seems to get destroyed, so the Image and Pixbuf hang around indefinitely.

I suspect this is a bug with GtkD since commenting everything out in SideBarRow still shows the same behavior so it doesn't appear to be a case of the code holding on to a reference. Having said that, I need to build a reproducer, it wouldn't be the first time a reproducer shows the problem is with me.

gnunn1 commented 6 years ago

I think I have tracked down the issue and opened an issue with the GtkD maintainer to have a look at it.

gnunn1 commented 6 years ago

Just a note to myself, I think another thing I could do to mitigate this plus optimize the workflow is simply re-use the ListBoxRows that are available instead of deleting all the rows and re-creating it everytime the session sidebar is shown. Since the majority of time the number of sessions is relatively constant this would mitigate, but not eliminate, potential memory losses plus slightly improve performance.

gnunn1 commented 6 years ago

I've checked in some code that should hopefully mitigate, but not completely eliminate, this issue. Please feel free to build the version in master and try it out.

PD-Extron commented 6 years ago

@gnunn1 Thanks for looking into this. I've been using tabs instead of the sidebar for the past week or two and there are no memory leaks that I can tell.

I would like to test your changes but I'm not sure how to build it. Do you have any instructions?

gnunn1 commented 6 years ago

Compiling it is pretty easy however testing it is a bit more challenging since the dependencies for gsettings is different in master then what was released. You would need to uninstall tilix first and do a temporary installation of it from the built version.

You need to have D installed on your system, depending on what distro you are running the way to get it will be different. I believe Debian has the ldc compiler available in an ldc package. Once you install that, compiling tilix is super simple:

dub build --build=release`
sudo ./install.sh

The install script installs it in /usr, after that run it with tilix

When you are finished testing it you can uninstall it with:

uninstall.sh