flayout navigation - how to deal with rasing memory?

Dani_S 3,316 Reputation points
2024-07-14T14:42:45.7166667+00:00

Hi,

I used flayout navigation. when navigate beween pages it consume alot of memory.

In net 8. Not relase the previous page.

Does to use GC.Collect()?

Is allowed ?

Thanks,

  public void Navigate(string navigateTo)

  {


  if (navigateTo == "InProcessPage")

  {

      var page = (Page)Activator.CreateInstance(typeof(InProcessPage));

      if (page != null)

      {

          this.Detail = new NavigationPage(page);

          NavigationPage.SetHasBackButton(Detail, false);

          inProcessButton.HasSelect = true;

          uploadButton.HasSelect = false;

          downloadButton.HasSelect = false;

          copyButton.HasSelect = false;

          scanHistoryButton.HasSelect = false;

          rulesButton.HasSelect = false;

          logsButton.HasSelect = false;

      }

  }

  else if (navigateTo == "DownloadPage")

  {

      var page = (Page)Activator.CreateInstance(typeof(DownloadPage));

      if (page != null)

      {

          this.Detail = new NavigationPage(page);

          NavigationPage.SetHasBackButton(Detail, false);

          downloadButton.HasSelect = true;

          uploadButton.HasSelect = false;

          inProcessButton.HasSelect = false;

          copyButton.HasSelect = false;

          scanHistoryButton.HasSelect = false;

          rulesButton.HasSelect = false;

          logsButton.HasSelect = false;

      }

  }

  else if (navigateTo == "CopyPage")

  {

      var page = (Page)Activator.CreateInstance(typeof(CopyPage));

      if (page != null)

      {

          this.Detail = new NavigationPage(page);

          NavigationPage.SetHasBackButton(Detail, false);

          copyButton.HasSelect = true;

          uploadButton.HasSelect = false;

          downloadButton.HasSelect = false;

          inProcessButton.HasSelect = false;

          scanHistoryButton.HasSelect = false;

          rulesButton.HasSelect = false;

          logsButton.HasSelect = false;

      }

  }

  **GC.Collect();**
```  }

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,208 questions
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,936 Reputation points Microsoft Vendor
    2024-07-17T06:54:16.74+00:00

    Does clear the navigation stack on disappering will solve the problem(with code suit to navigation)?

    var stack = Shell.Current.Navigation.NavigationStack.ToArray(); for (int i = stack.Length - 1; i > 0; i--) { Shell.Current.Navigation.RemovePage(stack[i]); }

    You use FlyoutPage, why you use shell navigation? By the way, FlyoutPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use FlyoutPage in a Shell app. For more information about Shell apps.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more