You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Microsoft.UI.Xaml.dll!00007FF60A67D0F3: 80070057 - E_INVALIDARG
Exception thrown at 0x00007FF881B12BDC (KernelBase.dll) in App2.exe: WinRT originate error - 0x80070057 : 'The parameter is incorrect.'.
Exception thrown at 0x00007FF881B12BDC in App2.exe: Microsoft C++ exception: winrt::hresult_invalid_argument at memory location 0x00000038262F9FD8.
Exception thrown at 0x00007FF881B12BDC in App2.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in App2.exe.
Expected behavior
No response
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002
Windows version
Windows 11 (21H2): Build 22000
Additional context
No response
The text was updated successfully, but these errors were encountered:
tom-huntington
changed the title
Can't Unload element after removing it from visual tree
Can't UnloadObject after removing it from visual tree
Nov 18, 2024
You can use x:Load to optimize the startup, visual tree creation, and memory usage of your XAML app. Using x:Load has a similar visual effect to Visibility, except that when the element is not loaded, its memory is released and internally a small placeholder is used to mark its place in the visual tree.
When an object is unloaded, it will be replaced in the tree with a placeholder. The object instance will remain in memory until all references have been released. The UnloadObject API on a Page/UserControl is designed to release the references held by codegen for x:Name and x:Bind. If you hold additional references in app code they will also need to be released.
UnloadObject sets x:Load. It is meant to optimize performance for objects in the visual tree, not as a "Dipsose" type of method to call on things you no longer want in the tree - which is what you are doing.
not as a "Dipsose" type of method to call on things you no longer want in the tree - which is what you are doing.
I want is a way to
to release the references held by codegen for x:Name
I'm only using it to remove things from the visual tree because that's the only situation when UnloadObject will work: i.e. It only works on objects (myButton) that haven't been previously removed from the visual tree.
I'm happy to manually remove the named elements, I'm trying to unload, from the visual tree
myStackPanel().Children().ReplaceAll({ });
but UnloadObject(myButton()); stills throws when I try to use it to release the references held by myButton()/x:Name.
tom-huntington
changed the title
Can't UnloadObject after removing it from visual tree
C++: Can't UnloadObject after removing it from visual tree
Nov 18, 2024
Describe the bug
I get an exception if I Unload an object after having removed from the visual tree.
This is only an issue in C++. I could not reproduce this in C#.
Is there a work around?
Steps to reproduce the bug
Expected behavior
No response
Screenshots
No response
NuGet package version
WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002
Windows version
Windows 11 (21H2): Build 22000
Additional context
No response
The text was updated successfully, but these errors were encountered: