slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.7k stars 614 forks source link

Unexpected memory allocation #6716

Closed PsycHead closed 3 weeks ago

PsycHead commented 3 weeks ago

Memory usage of Rust programs compiled with Slint seems unexpected:

  1. Memory does not seem to be freed after dropping all Slint related objects
  2. using QT as a back end, initial memory usage is high even before creating any windows

Example

A program running in the background for a while, then creating a window and eventually closing again. I made a minimal repo based on the Slint template to reproduce the issue ( https://github.com/PsycHead/slint-memory-test ).

Expected Behavior

  1. The program starts with a fairly low memory footprint (the executable)
  2. As the Window is drawn, more memory is allocated
  3. After dropping all Slint objects, the allocated memory is released

Current Behavior

RAM usage on my system (Arch Linux, Wayland) for all three program phases. (Phase - QT - Winit)

  1. Startup, no UI - 70MB - 2MB
  2. UI visible - 102MB - 167MB
  3. UI droppend - 107MB - 167MB

Note that memory is not freed after dropping the UI and that QT immediately increases the memory footprint by a lot.

Why is this an Issue?

My use case is a service that will run in the background and wait for a signal to occasionally show an interactive window. Consuming more than 100MB for a dormant program is not acceptable in that case.

Discussions #5854 and #3376 may be related. Adding SLINT_DESTROY_WINDOW_ON_HIDE=1 does nothing on my machine.