enisn / UraniumUI

Uranium is a Free & Open-Source UI Kit for MAUI.
Apache License 2.0
1.13k stars 131 forks source link

Memory Leaks Report #727

Closed usefulBeeing closed 2 months ago

usefulBeeing commented 2 months ago

I tested UraniumUI for possible leaks using a wrapper around MemoryToolkit. The result came as seen in the screenshot when tested against <material:AutoCompleteTextField />. I also came across other UI packages that did not leak, so if they can avoid those leaks, I'm sure UraniumUI could too!

_materialUI
enisn commented 2 months ago

Hi, thanks for the report 🎉🙏

Can you provide which platform you run tests on? AutoCompleteView has different implementations on each platform, so I can find where to start checking, thanks

usefulBeeing commented 2 months ago

Thank you @enisn for your quick response :rocket:. The SimplifiedLeakDetector wrapper I tested with is a .NET MAUI project. I added the two NuGet packages through Visual Studio Version 17.10.4.

_material3 _material4
enisn commented 2 months ago

I found the leak source.

The MemoryToolkit library warns because of the following Geometry instances. UraniumUI components always use the same instance of Geometry classes for optimization. Since they're a static field of a class, they won't be disposed. The tool you measure finds it and throws warning. https://github.com/enisn/UraniumUI/blob/92202bd81ff6bd32c177d2e9296c07619e1e7827/src/UraniumUI/Pages/UraniumShapes.cs#L7-L13

When I replace = operator with => all the warnings are gone. But this is not what I want. In this scenario each control will have different Geometry instance and they'll consume n times more memory according to number of components in the page

Still I'll take a look a deep memory analyze if it's better to use different instances or not