LGUG2Z / komorebi

A tiling window manager for Windows 🍉
https://lgug2z.github.io/komorebi/
Other
9.08k stars 182 forks source link

[BUG]: Memory leak in `transparency_manager` #863

Closed CtByte closed 4 months ago

CtByte commented 4 months ago

Describe the bug When the "transparency": true setting is used, there is a memory leak that happens when an inactive program cannot be transparent.


To Reproduce Steps to reproduce the behavior:

  1. Add "transparency": true and "transparency_alpha": 210 to the config
  2. Open a program that can be transparent and an other that cannot (ex: Visual Studio Community 2022).
  3. Observe komorebi.exe in the Task Manager
  4. When the program that cannot be transparent becomes inactive the memory consumption rises

I only found Visual Studio to not allow transparecy so far.

Microsoft Visual Studio Community 2022 (64-bit)
Version 17.9.7

Screenshots and Logs

Typical MEM is around 40 MB. After leaving Komorebi run for a while MEM is over 3 GB.

Screenshot 2024-06-01 222334

When I run Komorebi locally, it starts to spam this warning when VS becomes inactive.

2024-06-02T11:37:24.531516Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.532153Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.532317Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.532934Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.533093Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.533891Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.534000Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.534698Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.534864Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.535537Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.535667Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.536364Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)
2024-06-02T11:37:24.536459Z  INFO komorebi::transparency_manager: listening
2024-06-02T11:37:24.537126Z  WARN komorebi::transparency_manager: restarting failed thread: The parameter is incorrect. (0x80070057)

Operating System

OS Name:                   Microsoft Windows 11 Pro
OS Version:                10.0.22631 N/A Build 22631
LGUG2Z commented 4 months ago

Of course it would be a Microsoft application 🙃

I think we can probably refactor this to log the error instead of propagate it to the thread handler which should stop the global state tracker from filling up on every thread restart.

CtByte commented 4 months ago

I'll be happy to test again so you are not forced to dirty your system with VS 😉

To be fair, there might be other programs out there, but Microsoft VS is one of them for sure.

LGUG2Z commented 4 months ago

The commit above should address the memory ballooning issue 🤞

CtByte commented 4 months ago

It is working. The output is now:

2024-06-02T21:23:18.320713Z  INFO process_event{event=FocusChange(SystemForeground, Window { hwnd: 265250 })}: komorebi::process_event: processed: (hwnd: 265250, title: Developer PowerShell Visual Studio Community 2022 17.9.34902.65, exe: WindowsTerminal.exe, class: CASCADIA_HOSTING_WINDOW_CLASS)
2024-06-02T21:23:18.322339Z ERROR komorebi::transparency_manager: failed to make unfocused window 265250 transparent: The parameter is incorrect. (0x80070057)

Thank you very much for the quick response as always!