How to Properly Release Window #10084
-
It seems that memory is not being properly released when opening and closing windows. Sorry, my question has changed a little from the beginning. At first, I thought that the memory was not being released because the destructor was not being called, but it was my mistake that the destructor was not being executed. The window is simple and empty. xaml <?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="WindowTest.BlankWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WindowTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
</Window> .h struct BlankWindow : BlankWindowT<BlankWindow>
{
BlankWindow()
{
this->AppWindow().SetPresenter(winrt::Microsoft::UI::Windowing::AppWindowPresenterKind::CompactOverlay);
this->AppWindow().Resize({ 300, 300});
this->AppWindow().IsShownInSwitchers(false);
}
~BlankWindow()
{
}
}; idl
UserControl void UserControl::myButton_Click( IInspectable const&, RoutedEventArgs const& )
{
BlankWindow sub_window;
sub_window.Activate();
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
The destructors certainly do run, so it would be nice to know what you are doing. A big thing to remember about these windows is that they are reference counted. This means that the lifetime is controlled by any strong references held on the object. If the window isn't being destroyed then it means that there is a reference being held somewhere. This means that without more information on the code you are using, then it isn't possible to figure out if this is a bug or a mistake. Are you releasing all of the references that you are holding on these windows? |
Beta Was this translation helpful? Give feedback.
When I wrote my previous post, I didn't do my normal thing of stepping away and thinking about things for a while. Because of this, my previous post is a bit of an incomprehensable mess, I apologise about that. But I don't believe this is a bug.
The following video is a shorter version of my last video in my previous post.
2024-10-20.11-34-19.mp4
In this case, do you notice how the memory stays almost constant? It is also higher on my system, but I think that is due to GPU driver differences. If there was a per window memory leak then memory wouldn't be staying constant.
In the following video, I am opening 10 windows in quick succession and then closing them all again.
2024-…