Skip to content
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

Closing TabViewItems Does Not Free Used Memory #2938

Closed
lukeblevins opened this issue May 26, 2019 · 3 comments
Closed

Closing TabViewItems Does Not Free Used Memory #2938

lukeblevins opened this issue May 26, 2019 · 3 comments
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️

Comments

@lukeblevins
Copy link
Contributor

I'm submitting a...

Bug report (I searched for similar issues and did not find one)

Current behavior

When a user creates a new TabViewItem with a Frame as content, RAM usage will increase for each created item. However, closing one or more of these tabs will keep RAM usage exactly the same with no decrease.

Expected behavior

For many application scenarios, the user expects this memory usage to decrease when the tabs are closed.

Minimal reproduction of the problem with instructions

https://1drv.ms/f/s!AvgU7aa_XojB4kTts9UV5xXGWNfD
Try to create new tabs and monitor memory usage as they are closed.

Environment

Nuget Package(s): Microsoft.Toolkit.Uwp.UI.Controls
Package Version(s): v5.1.1

Windows 10 Build Number:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [ ] October 2018 Update (17763)
- [x] May 2019 Update (18362)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Fall Creators Update (16299)
- [ ] April 2018 Update (17134)
- [x] October 2018 Update (17763)
- [x] May 2019 Update (18362)
- [ ] Insider Build (xxxxx)

Device form factor:
- [x] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [x] 2019 (version: 16.0.3)
- [ ] 2017 Preview (version: )

@lukeblevins
Copy link
Contributor Author

lukeblevins commented Jun 1, 2019

I presume this is because TabView is based off of ListViewBase (and a StackPanel as the ItemsPanel) which does not seem to dispose of its items when cleared.

@lukeblevins
Copy link
Contributor Author

I've figured out what causes this behavior to occur. The lack of garbage collection seems to happen when I add TabViewItems to the TabView rather than just setting the ItemSource to an ObservableCollection. (Which makes sense...) I'm going to close this issue now.

@premiaware
Copy link

premiaware commented Jun 5, 2019

The same problem with memory Leaks is when in the xaml to add the TabViewItems with inside Usercontrol for example:

    <TabView
        TabWidthBehavior="Actual"
        CanCloseTabs="False"
        IsCloseButtonOverlay="False"
        CanDragItems="False"
        CanReorderItems="False"
        AllowDrop="False">
        <controls:TabViewItem>
            <local:RicercaAnagraficaTabAnagraficaUserControl />
        </controls:TabViewItem>
   ……..

In this case when the page that contain the tabView is Disposed the Tabview maintain the usercontrol live.
My solution for fix the problem is derive the TabView

public class TabViewExt : TabView
{
public TabViewExt ()
{
this.DefaultStyleKey = typeof(TabView);
this.Unloaded += TabViewExt_Unloaded;
}

    private void TabViewExt_Unloaded(object sender, RoutedEventArgs e)
    {
        if (this.Items != null)
            this.Items.Clear();
    }
}

If i call Items.Clear(); all working well and the usercontrol is disposed.

@michael-hawker michael-hawker added bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️ labels Jul 26, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Nov 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior controls 🎛️
Projects
None yet
Development

No branches or pull requests

3 participants