-
Notifications
You must be signed in to change notification settings - Fork 506
Update DesktopWindowXamlSource to describe how to avoid leaks #2054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: docs
Are you sure you want to change the base?
Changes from all commits
abca97e
9ef1b6d
d3a7f9b
e053556
756d269
7fc5149
8578a5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,25 @@ Equivalent WinUI method: [Microsoft.UI.Xaml.Hosting.WindowsXamlManager.Initializ | |
An object that contains a reference to the UWP XAML framework. | ||
|
||
## -remarks | ||
Call this method to initialize the internal UWP XAML framework for the current thread in a desktop application in which you want to host [Windows.UI.Xaml.UIElement](../windows.ui.xaml/uielement.md) objects in a [DesktopWindowXamlSource](desktopwindowxamlsource.md). You only need to explicitly call this method if your application creates the **Windows.UI.Xaml.UIElement** objects before it creates the **DesktopWindowXamlSource** object that will host them. Your application should typically should call this method when the parent UI object that hosts the **DesktopWindowXamlSource** is instantiated. | ||
Call this method to initialize the internal UWP XAML framework for the current thread in a desktop application in which you want to host [Windows.UI.Xaml.UIElement](../windows.ui.xaml/uielement.md) objects in a [DesktopWindowXamlSource](desktopwindowxamlsource.md). Call this method if your application creates the **Windows.UI.Xaml.UIElement** objects before it creates the **DesktopWindowXamlSource** object that will host them, or if your program uses XAML from more than one thread. | ||
|
||
If you create a **DesktopWindowXamlSource** object before you create the **Windows.UI.Xaml.UIElement** objects that will be hosted in it, you don’t need to call this method. In this scenario, the UWP XAML framework will be initialized for you when you instantiate the **DesktopWindowXamlSource** object. | ||
This method must be called before creating the **DesktopWindowXamlSource** on the thread. | ||
|
||
This method returns a [WindowsXamlManager](windowsxamlmanager.md) object that contains a reference to the UWP XAML framework. You can create as many **WindowsXamlManager** objects as you want on a given thread. However, because each object holds a reference to the UWP XAML framework, you should **Close** (**Dispose** in .NET) the objects to ensure that XAML resources are eventually released. | ||
This method returns a [WindowsXamlManager](windowsxamlmanager.md) object that contains a reference to the UWP XAML framework for the current thread. It is safe to call this method multiple times, it will return the same instance if one is active. | ||
You must destroy the instance after destroying the **DesktopWindowXamlSource** instances. Note, after releasing this object a message loop must be run to finish the resource rundown, otherwise the associated resources will be leaked. | ||
|
||
```cpp | ||
|
||
// Break the cycle between the WindowsXamlManager and the DesktopWindowXamlSource. | ||
m_xamlSource.Close(); | ||
m_xamlManager = nullptr; | ||
|
||
// Drain the message queue after releasing WindowsXamlManager since rundown is async | ||
while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) |
||
{ | ||
ChrisGuzak marked this conversation as resolved.
Show resolved
Hide resolved
|
||
::DispatchMessageW(&msg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ::DispatchMessageW(&msg); |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. } |
||
``` | ||
|
||
## -see-also | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.