Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Memory get leaks when applying style from Application resources #14995

Open
vigneshrameshsync opened this issue Dec 21, 2021 · 1 comment
Labels
s/unverified New report that has yet to be verified t/bug 🐛

Comments

@vigneshrameshsync
Copy link

Description

I have created a simple custom control that is inherited from TemplateView, added one label (label1) in its ControlTemplate and Style (LabelStyleExt) property for customizing its Style. Hooked the PropertyChanged for the LabelStyleExt property to handle the dynamic changes.

In the sample level, defined a Style for CustomControl in Application resources, created simple ContentView, added the CustomControl in it and bound the Style.

NOTE: Issue reproducing in all the 3 platforms.

Steps to Reproduce

  1. Run the sample
  2. Click the "New View" button multiple times

Expected Behavior

Old CustomControl instances will be removed from the memory properly.

Actual Behavior

CustomControl instances get increased in the memory on every button click.

Basic Information

Version with issue:
Last known good version:
Platform Target Frameworks:
Android: Android SDK version 9.0 (API 28)
UWP: Windows 10, version 2004 (10.0; Build 19041)
NuGet Packages:
Xamarin.Forms version: 5.0.0.2196
Xamarin.Essentials version: 1.7.0
Microsoft.NETCore.UniversalWindowsPlatform version: 6.2.12
NETStandard.Library version: 2.0.3
Affected Devices:
Nexus 5X - API 27 emulator
Windows 10 pro 64-bit (10.0, Build 19042)

Environment

Show/Hide Visual Studio info

Microsoft Visual Studio Professional 2022 Preview
Version 17.0.0 Preview 4.1
VisualStudio.17.Preview/17.0.0-pre.4.1+31717.71
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Professional

Visual C++ 2022   00476-70000-00000-AA978
Microsoft Visual C++ 2022

.NET Core Debugging with WSL   1.0
.NET Core Debugging with WSL

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   17.0.616.20688
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   17.0.616.20688
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   17.0.616.20688
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.4000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.0.616.20688
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.4000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.0.0-4.21458.2+2bfff7b9348e779628a06b86af04b5239d3a926d
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

Cookiecutter   17.0.21243.2
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus   1.2.6 (master@34d6af2)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

Linux Core Dump Debugging   1.0.9.31710
Enables debugging of Linux core dumps.

Microsoft Azure Hive Query Language Service   2.6.4000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   17.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.6.4000.0
Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio   2.9
Support for Azure Cloud Services projects

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.1.134+45632ee938.RR
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.2
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   17.0.11 (54f19d2)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.30901.1 Commit Hash:2ce65f585c66dbd15240cf57f8e995513c270b0b
Adds support for developing and debugging Node.js apps in Visual Studio

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

Office Developer Tools for Visual Studio   17.0.31617.00
Microsoft Office Developer Tools for Visual Studio

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python - Profiling support   17.0.21243.2
Profiling support for Python projects.

Python with Pylance   17.0.21243.2
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Razor (ASP.NET Core)   17.0.0.2143108+3355b17aa26a41735ddf03b9fd3f71df166c0411
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62109.15100
Microsoft SQL Server Data Tools

Syncfusion Reference Manager   17.1.0.30
A useful add-in for adding and migrating Syncfusion Assembly References for Windows Forms, WPF, and Silverlight projects.

Syncfusion UWP Project Templates   19.3.0.43
Project to create an Universal Windows Application using Syncfusion Products.

Syncfusion.VSExtension.Troubleshooter   19.3.0.36
Add-in for Troubleshooting the Syncfusion projects.

SyncfusionMenu Extension   1.0
SyncfusionMenu Visual Studio Extension Detailed Info

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.0901.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.0.0-4.21458.2+2bfff7b9348e779628a06b86af04b5239d3a926d
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android)   17.0.31709.430
Visual C++ for Cross Platform Mobile Development (Android)

Visual C++ for Linux Development   1.0.9.31710
Visual C++ for Linux Development

Visual F# Tools   17.0.0-beta.21431.1+a7e1ca9200c21fd832dd9829fe1c655b69424ae8
Microsoft Visual F# Tools

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

Visual Studio Container Tools Extensions   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   17.0.0.266 (d17-0@56a1e79)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   17.0.0.101 (remotes/origin/main@533d7d10b)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   17.0.11 (a04c9af)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   12.0.99.13 (main/fe2e7e6)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: c633fe9
    Java.Interop: xamarin/java.interop/main@b7982e4
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.36.0@a575761
    Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9b658b2


Xamarin.iOS and Xamarin.Mac SDK   14.99.0.598 (11838db7d)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Not applicable

Screenshots

image

Reproduction Link

StyleMemoryLeak.zip

Workaround

If we used explicit style (expect in Application resources) / implicit style, then the leak is not occurring.

@vigneshrameshsync vigneshrameshsync added s/unverified New report that has yet to be verified t/bug 🐛 labels Dec 21, 2021
@rjhind
Copy link

rjhind commented Mar 11, 2022

I'm seeing memory leaks which may be related. All my resources are in App.xaml. I create and remove popups but they are being kept around. In my case, it's mostly down to shapes. Path hooks the PropertyChanged of it's geometry which is coming from an App.xaml resource. Shape base class hooks it's brush which in my case are coming from App.xaml.

These events are only unhooked when the property is changed but not when controls are removed from the UI and ready to be collected.

Only solution for now may be to include all resources in each control but I'm not sure what overhead that will add.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

2 participants