Comments (3)
For the first leak you mention here, it is a harmless leak.
When you create an instance of Application, via App, the runtime stashes an extra reference to Application somewhere. This is never released when the process exits. You can verify this by defining a destructor in App and placing a breakpoint in it, the breakpoint is never hit.
If you do some nasty things and release that final reference to App, the leaks almost completely go away. For example, if I override the Xaml defined entry point function and use the following:
#include "pch.h"
#include "App.xaml.h"
void nasty_stuff_that_frees_the_application(const winrt::Microsoft::UI::Xaml::Application &app);
void check_process_requirements();
int APIENTRY wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
{
check_process_requirements();
auto flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
flags = (flags & 0x0000ffff) | _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag(flags);
winrt::Microsoft::UI::Xaml::Application app = nullptr;
winrt::Microsoft::UI::Xaml::Application::Start(
[&app](auto &&)
{
app = winrt::make<winrt::Meh::implementation::App>();
});
nasty_stuff_that_frees_the_application(app);
app = nullptr;
return 0;
}
The following is the left over detected blocks of memory left allocated:
Detected memory leaks!
Dumping objects ->
{406} normal block at 0x000002D3241429D0, 32 bytes long.
Data: <0 E E > 30 86 45 00 F6 7F 00 00 00 86 45 00 F6 7F 00 00
{272} normal block at 0x000002D324142E50, 24 bytes long.
Data: < - > 18 2D 07 17 FF 7F 00 00 01 00 00 00 00 00 00 00
Object dump complete.
The program '[15928] Meh.exe' has exited with code 0 (0x0).
I'm not going into how I released that last reference to Application because it is guaranteed to leave a dangling pointer somewhere in the Xaml runtime. While it doesn't cause problems now for short periods after it is deleted, there is no guarantee that there will never be a use after free in the future. If you want to work it out yourself, it is basically obtaining the ABI interface and releasing it without an AddRef or QI. But this is certainly not something that you should do, I'm only doing it here to illustrate a point.
The remaining two blocks could be related to the dispatcher queue, which I don't believe gets shut down either. But these are harmless because the amount of blocks does not grow and Windows will reclaim the memory when the process' heap gets destroyed when the process exits. However, I understand that these leaks can get in the way of debugging.
from microsoft-ui-xaml.
Thank you, Darran, for clarifying the facts. That at least explains that part. And yes, of course this makes troubleshooting more difficult and should definitely be fixed.
However, the second problem pointed out by the application is much more problematic (see points 5 and 6). The constantly growing memory requirements of the application will paralyse the system in a relatively short time. For our actual application, the memory problem is even worse, as it has to update an extensive GUI at very short intervals. This is currently preventing us from delivering the product and is absolutely critical.
It may not be a memory leak in the classic sense, but only in the sense that the memory is apparently still being released correctly before the app is exited. But not as long as the app is running. So it's just a question of timing.
Of course, it is important that this problem is fixed, because it is serious. For the moment, however, an explanation would help me, and above all a workaround.
from microsoft-ui-xaml.
In my opinion, an application that generates its own graphical elements and updates their display regularly is a standard use case. If such applications cause the user systems to crash, this is highly critical. Accordingly, this problem should also be classified here!
Is there anyone in the Microsoft team who can help with this?
from microsoft-ui-xaml.
Related Issues (20)
- How to set a control/element especially MediaPlayerElement to full screen in WinUI3 HOT 2
- ListView with Single selection mode can have two selected items. HOT 2
- Crashing when binding to control resources HOT 4
- TitleBar doesn't show Subtitle/Header/Content/Footer HOT 7
- New TitleBar Control Content/Footer/Header/Subtitle does not Shown HOT 2
- Hide Window does not raise VisibilityChanged event
- When AOT was released, the XAML implicit conversion failed HOT 4
- ItemsSource breaks with AOT HOT 3
- TitleBar API feedback HOT 32
- TitleBar doesn't support TitleBarHeightOption.Standard HOT 1
- Can't select text from TextBox/AutoSuggestBox set as content in TitleBar with the cursor HOT 7
- High CPU Usage in WinUI App When Screen is Locked on Remote Desktop Due to DWMCOREI.dll HOT 4
- Enabling NumberBox AcceptsExpression ignores numbers smaller than 1 when entered in scientific notation HOT 4
- Expanders need a button on the arrow to assist with the narrator. HOT 2
- WinUI 3 ContentDialog declaration in xaml as Flyout does HOT 2
- ListView doesn't respect Visibility of contents HOT 4
- Able to change the window height even if IsResizable is false but ExtendsContentIntoTitleBar is true HOT 3
- AOT fails with Dictionary<T, U> in 1.6 Experimental HOT 3
- DefaultTitleBarShouldMatchAppModeTheme does not respect RequestedTheme HOT 3
- ContentDialog has no show animation in 1.6-exp1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft-ui-xaml.