0

With this code I am creating new view:

CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        Frame frame = new Frame();
        frame.Navigate(typeof(SecondaryPage), null);
        Window.Current.Content = frame;
        // You have to activate the window in order to show it later.
        Window.Current.Activate();

        newViewId = ApplicationView.GetForCurrentView().Id;
    });
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);

When I close that new window, and run code again, and again I close that new one and again I open another window, memory usage in windows is getting larger and larger...so, I think all the windows are not closed, but just hidden actually...

So, there are 2 ways I am trying:

  1. Try to actually "kill" the closed window
  2. Try to re-show hidden window and make it's content different...

I just want there to be only 2 windows, main and this newly created... Any suggestion on how to do this?

Edit:

This is what it looks like when I use this example https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MultipleViews

These are 3 screenshots with this app.

This is memory consumption when app is started:

This is after I add 4 views:

And this is when I open and close each one of them:

So, even in their example memory usage is rising...

user3239349
  • 877
  • 1
  • 12
  • 33

1 Answers1

1

When you close a window it is kept in the recently used windows list in case it is needed again. If you know you won't need it again (or want/need to reclaim the memory) you can close it by calling Window.Current.Close(); after the ApplicationView.Consolidated event is called on that view.

There's description of this in this article on the "buildingapps" blog.
There's also a (quite complicated IMO) example in the UWP samples repository.

Matt Lacey
  • 65,560
  • 11
  • 91
  • 143