slint-ui / slint

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

Freezing Issue #1656

Closed saturn77 closed 2 years ago

saturn77 commented 2 years ago

I have a slint-ui GUI that I am working on. During the testing of the GUI, while running in Windows 10, it typically freezes after about 5 to 7 minutes of running. I have used the task manager to check the memory usage of the GUI and it fluctuates between about 55 MB and 61 MB.

The .exe file itself is about 6 MB. Typically I develop on Linux but am also trying this out on Windows. I've notice that in task manager that if I associate higher priority to the task it typically runs a little longer before freezing.

Now in the main part of the GUI, I use several Weak reference to handle callbacks both from a handler viewpoint and an invoke viewpoint. I just wonder if I may be doing something wrong here. The code is at https://github.com/saturn77/magnet

Thanks. James

ogoffart commented 2 years ago

What do you exactly means by "freezing"? Could you upgrade to Slint 0.3? A leak has been fixed, and it is also using a newer version of winit. Can you run attached to a debugger, and get a backtrace when frozen?

saturn77 commented 2 years ago

Thanks for the feedback. I did upgrade to Slint 0.3 and that does appear to fix the issue.

Also, from the initial question, what I meant by "freezing" is that I get the classic Windows OS "application not responding" and the GUI controls were frozen and I end up having to shut down the application. This behavior did seem to indicate a leak, as the memory usage would spike and generally increase.

Now when I run the current GUI with Slint 0.3, it appears that the memory usage actually goes down over time. image

It starts up at around 76 MB, then drifts down slowly to around 55 to 50 MB. Overall, it appears to be running fine and I am going to let the GUI run for 8 to 12 hours just to make sure.

Overall, my apologies for not having Slint 0.3 to start. I started this project quite some time ago and did not upgrade Slint when I started to resume work on it. Finally, I wan to make sure the use of Weak references in the main code is okay, in terms of using multiple uses of the ui handle or pointer (I know that I will need to add code to unwrap the Result<> now)

Multiple Weak

I will have multiple unique callbacks and just want to handle this correctly. Thanks. James

ogoffart commented 2 years ago

yes, that looks alright.

You can make the code shorter by using the Weak::upgrade_in_event_loop function.

And yes, Slint 0.3 return Result, but you can just .unwrap() it.

ogoffart commented 2 years ago

I'm closing this issue then since the freezing issue seems gone. Feel free to re-open if it still happen.