telegramdesktop / tdesktop

Telegram Desktop messaging app
https://desktop.telegram.org/
Other
25.85k stars 5.11k forks source link

The app consumes an enormous amount of RAM after a short period of use. #25189

Closed farivar-tabatabaei closed 1 year ago

farivar-tabatabaei commented 1 year ago

Steps to reproduce:

Usual Memory Leak:

  1. Open the Telegram app
  2. watch some videos or any media
  3. scroll through some channels posts

Extreme Memory Leak:

  1. Close the app without clearing the ram manually
  2. run it again
  3. watch some media
  4. scroll through some channels posts

Configuration:

Some Notes:

I'm not aware of how much ram the app should use technically, but using 6.5 GB - 8 GB of ram after running for 15 minutes doesn't look very reasonable.

I think it's an old memory leak problem of the telegram desktop that happens after playing video files or watching photos that have been reported in previous versions, like since 2015, and have been discussed a lot before but it has not been fixed since then.

my issue can be related to #1317, #7361, #7280, #10327, #10516, and #16084, I know the actual technical reason may be different, but apparently, all these issues are reporting the same kind of problem over and over again.

Also, using apps like IOBit Advanced SystemCare's ram cleaner works without affecting the app's performance or causing it to crash, so it confirms the memory leak that we all know exists, so is there a technical limitation or something that no one has fixed this problem? And sometimes when you close the app the data in the RAM is still there and does not get cleaned by the garbage collector until I call the ram cleaner, so if I open the app again without clearing the ram it just uses more and more and if you do it a couple of times it fills up the entire ram till there is no more space in it.

And one more thing that I'm not entirely sure of is that clearing local storage using the app's built-in function can reduce ram usage.

If any more information is required let me know.

ilya-fedin commented 1 year ago

25162?

farivar-tabatabaei commented 1 year ago

25162?

Not exactly, in #25162, its-monotype says that this problem doesn't happen for him always, but in my case, it happens every single time I use the Telegram desktop app. So it is a more severe case of his problem, and also the process of filling the ram continues until there is no more ram left and the Telegram desktop app is now practically unusable for me.

ilya-fedin commented 1 year ago

Maybe you enabled hardware decoding feature? It's very bugged

farivar-tabatabaei commented 1 year ago

Maybe you enabled hardware decoding feature? It's very bugged

It was enabled at first, but it came to my mind that HW decoding may be the cause of the problem so I turned it off but nothing changed and it didn't fix the problem.

farivar-tabatabaei commented 1 year ago

Maybe you enabled hardware decoding feature? It's very bugged

Found it!!! It's the ANGLE graphics backend, when it's set to Direct3D 11 or auto that chooses Direct3D 11 and you play even a single 4MB video the ram just ramps up gigabytes, but when it's set to OpenGL or Direct3D 9 it's perfect.

And I found another problem in the process that is when I set ANGLE graphics backend to D3D11on12 and play a video the video player doesn't show up at all, it's there as an overly because I can't click on anything and the audio is playing, so yep here is another problem.

FIX:

ilya-fedin commented 1 year ago

OpenGL is likely no-op and actually disables ANGLE

farivar-tabatabaei commented 1 year ago

OpenGL is likely no-op and actually disables ANGLE

As I said Direct3D 9 works too even with HW decoding enabled.

Anyway, I tested the app on the same hardware and as you can guess the results were the same, so on the second windows machine I changed the graphics card driver to the latest DCH driver available and it fixed the problem, so I don't exactly know why, but apparently, the Direct3D 11 problem is with AMD's legacy drivers no the DCH one's.

Aokromes commented 1 year ago

then 3rd party bug?

farivar-tabatabaei commented 1 year ago

then 3rd party bug?

I'm not sure exactly, I should look into it deeper, but everything aside, the memory leak bug is there, and as I mentioned earlier there were and are many complaints about this memory leak, and actually, one them that ilya-fedin mentioned is about the recent version, so I'll keep looking and also I'll keep an eye on #25162 till its-monotype provide more information, thanks, guys.

ilya-fedin commented 1 year ago

His leak may be due to another reason. If it's the same reason then there's no other fix then blacklisting your and his graphics driver.

farivar-tabatabaei commented 1 year ago

OpenGL is likely no-op and actually disables ANGLE

As I said Direct3D 9 works too even with HW decoding enabled.

Anyway, I tested the app on the same hardware and as you can guess the results were the same, so on the second windows machine I changed the graphics card driver to the latest DCH driver available and it fixed the problem, so I don't exactly know why, but apparently, the Direct3D 11 problem is with AMD's legacy drivers no the DCH one's.

Nope, It's there again, even with the legacy drivers, I wonder why I took some time to show up 🤷‍♂️.

ilya-fedin commented 1 year ago

Try to disable both ANGLE and HW decoding

pleabargain commented 1 year ago

v v4.5 30.12.22 win 10 Telegram does not have focus it is not running in the foreground but it's consuming 500MG of memory image

ilya-fedin commented 1 year ago

500 MB is ok, it's the average tdesktop consumption in most setups

Igorgro commented 1 year ago

I've just runned Telegram on Arch Linux and it is already using 1.1Gb of RAM image

nikelborm commented 1 year ago

Same thing for me on latest arch + gnome 43 And it is just after the start

after some runtime it becomes up to 1.5 gb

Screenshot from 2023-03-09 02-44-11

john-preston commented 1 year ago

@Igorgro @nikelborm Please check if it is better in beta 4.6.9, there were unneeded allocations in colored custom emoji sets, if we're lucky that was your case.

nikelborm commented 1 year ago

I've run binary from this release and it now takes even more RAM https://github.com/telegramdesktop/tdesktop/releases/tag/v4.6.9 Screenshot from 2023-03-11 21-20-21

nikelborm commented 1 year ago

This is consumption after i return back to 4.6.5 Screenshot from 2023-03-11 21-47-54

Igorgro commented 1 year ago

I agree with previous commenters - looks like the app uses more and more ram after each release. It consumes even more ram than vscode (which is written in electron)

ilya-fedin commented 1 year ago

Maybe you're using a third party build with bad allocator? изображение

nikelborm commented 1 year ago

@ilya-fedin How can it be third-party build if I downloaded it from the provided link (official release page on github)?

I've run binary from this release and it now takes even more RAM https://github.com/telegramdesktop/tdesktop/releases/tag/v4.6.9

ilya-fedin commented 1 year ago

Well, I asked @Igorgro, but mainly because I saw suspicious /usr/bin/telegram-desktop path on your screenshot, yes

ilya-fedin commented 1 year ago

I also heard that some GPU drivers add used VRAM to the used RAM value on Linux (Intel?), so it may be hardware dependent. Personally I have AMD hardware.

nikelborm commented 1 year ago

@ilya-fedin I'm using arch notebook with no additional GPU (CPU graphics)

And by the way I checked memory consumption on latest version from pacman and it is significantly lower now

Screenshot from 2023-03-27 10-58-44

ilya-fedin commented 1 year ago

I'm using arch notebook with no additional GPU (CPU graphics)

that is not really a helpful information, integrated GPU is a GPU from software point of view.

nikelborm commented 1 year ago
screenfetch 
                   -`                 
                  .o+`                 nikel@archhost
                 `ooo/                 OS: Arch Linux 
                `+oooo:                Kernel: x86_64 Linux 6.2.8-arch1-1
               `+oooooo:               Uptime: 2d 3h 59m
               -+oooooo+:              Packages: 1427
             `/:-:++oooo+:             Shell: bash 5.1.16
            `/++++/+++++++:            Resolution: 3840x2560
           `/++++++++++++++:           DE: GNOME 43.4.1
          `/+++ooooooooooooo/`         WM: Mutter
         ./ooosssso++osssssso+`        WM Theme: 
        .oossssso-````/ossssss+`       GTK Theme: Adwaita-dark [GTK2/3]
       -osssssso.      :ssssssso.      Icon Theme: Adwaita
      :osssssss/        osssso+++.     Font: Noto Sans,  10
     /ossssssss/        +ssssooo/-     Disk: 128G / 457G (29%)
   `/ossssso+/:-        -:/+osssso+-   CPU: AMD Ryzen 7 5800H with Radeon Graphics @ 16x 3.2GHz
  `+sso+:-`                 `.-/+oso:  GPU: AMD/ATI Cezanne [Radeon Vega Series / Radeon Vega Mobile Series]
 `++:.                           `-/+/ RAM: 9624MiB / 13830MiB
 .`                                 `/
ilya-fedin commented 1 year ago

3840x2560

Ah, you have HiDPI hardware, that pretty explains RAM usage: tdesktop caches interface parts a lot in order to stay perfomant while using CPU-based rendering (tdesktop is not capable of GPU rendering outside of media viewer and calls window and even there it's partial), the more scaling you have, the bigger resolution of raster caches in RAM are, the more RAM usage. This is pretty intended behavior.

Also, tdesktop predates modern HiDPI practices and operates in a global scale factor from the largest scale factor of all monitors in the system. I.e. if you have a 1x, a 2x and a 3x monitor in the system, tdesktop will generate 3x pixmaps no matter which screen tdesktop window on with raster downscaling of system or Qt (actually all the graphics in tdesktop is raster, but thanks to caches the vector drawing operations in code become raster images as well).

nikelborm commented 1 year ago

But it still does not explain why it was like 1.5 GB of RAM

Now it is about 600 Mb on the same 4k monitor

Have developers removed all the caches in few latest versions?

ilya-fedin commented 1 year ago

Have developers removed all the caches in few latest versions?

As far as I'm aware, no. Although for me it's always were and is 480M at start.

MaxRev-Dev commented 1 year ago

Telegram 4.7.1 Windows 11 (22H2)

Memory Leak UPD: I can confirm that the ANGLE backend with DirectX 11 causes this. FIX: Settings > Advanced > Switch ANGLE from Auto to DirectX 9 or OpenGL See OP comment: https://github.com/telegramdesktop/tdesktop/issues/25189#issuecomment-1279702425

Sometimes happens after a computer is idle for a long time. After a startup, it also uses 2GB+ RAM. It can't be hidden in a tray with that amount of RAM. I have to close the app when I don't use it(

How you can reproduce it:

image

john-preston commented 1 year ago

@farivar-tabatabaei @MaxRev-Dev Please check the latest beta 4.8.11:

https://github.com/telegramdesktop/tdesktop/releases/tag/v4.8.11

On Windows with Direct3D 11 backend for ANGLE. I hope it won't leak memory anymore, I've updated ANGLE and found a workaround for strange memory allocations.

github-actions[bot] commented 1 year ago

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.