Bug 61027 - UWP: StackLayouts leaks memory
Summary: UWP: StackLayouts leaks memory
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.5.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-12-07 17:53 UTC by Balázs Bónis
Modified: 2018-02-12 18:22 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Project to reproduce the issue (1.29 MB, application/x-zip-compressed)
2017-12-07 17:53 UTC, Balázs Bónis

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Balázs Bónis 2017-12-07 17:53:15 UTC
Created attachment 25939 [details]
Project to reproduce the issue

On UWP with Xamarin.Forms pushing and then popping a page with stacklayouts on it to the navigation stack several times will leak memory. This is quite possibly not a replicate of 45593, but instead that exact same error that was never fixed. The Xamarin.Forms version mentioned in that leaks memory just as 

Either take the sample project attached, or create a simple one with the following setup:
- The main app should have a NavigationPage with the main page wrapped inside
- That main page should have a listview of elements
- Clicking on any of those elements should take the user to another page (call it details page), by pushing it to the stack
- Details page should have a back button that will pop the top of the navigation stack and taking it back to the main page

This navigation back-and-forth has to be done several times to see the memory usage increase. The problem is that the memory will never be released, GC will not collect it, even by forcing from either code or from the profiler.

You can take a snapshot in the profiler when the app starts and then navigate to a page and then back maybe 20, 30 times. Take another snapshot again, and then let VS analyse the difference.

Over longer periods of time this leads to crashes in every single UWP app with Xamarin.Forms.

=== NOTE
This seems to be an UWP-only problem, I could not get this to be reproduced in iOS

Memory usage should normalise.

=== Visual Studio
Microsoft Visual Studio Enterprise 2017  (Enterpricy)
Version 15.4.4
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Visual Basic 2017   00369-60000-00001-AA750
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA750
Microsoft Visual C# 2017

Visual F# 4.1   00369-60000-00001-AA750
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.9.00809.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30925.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services   1.0
Provides languages services for ASP.NET Core Razor.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   4.7.4-pre (c2d89eb)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

TypeScript tools for Visual Studio

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Universal Windows Apps   15.0.27004.2008
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.IoT   1.0
Package with IoT components for Visual Studio

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin (34c1b6c)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK (HEAD/c2a33d8ea)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK (51128b8)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

=== OS
Windows 10
Comment 1 Samantha Houts [MSFT] 2017-12-07 18:08:41 UTC
Thank you for your submission. At this time, all new reports should be made on the Xamarin.Forms GitHub Issues repository. Please resubmit this report at https://github.com/xamarin/Xamarin.Forms/issues. This Bugzilla report will now be closed and will not be monitored.
Comment 2 Samantha Houts [MSFT] 2018-02-12 18:22:10 UTC