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

[Bug] [Android] - Live Visual Tree leak when View removed from AbsoluteLayout.Children #14371

Open
usausa opened this issue Jun 27, 2021 · 0 comments

Comments

@usausa
Copy link

usausa commented Jun 27, 2021

Description

When dynamically view added or removed from AbsoluteLayout.Children, View is removed from the Children, but the item remains in the Live Visual Tree.

Depending on the order of Add/Remove, there are cases where the problem will occur and cases where it will not.

Steps to Reproduce

  1. Here is the source
  • MainPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="VisualTreeTest.MainPage"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <AbsoluteLayout x:Name="Container" Grid.Row="0" />

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Button
                Grid.Column="0"
                Clicked="Button1OnClicked"
                Text="View1" />
            <Button
                Grid.Column="1"
                Clicked="Button2OnClicked"
                Text="View2" />
        </Grid>
    </Grid>

</ContentPage>
  • MainPage.xaml.cs
namespace VisualTreeTest
{
    using System;
    using System.Diagnostics;

    using Xamarin.Forms;

    public partial class MainPage : ContentPage
    {
        private View current;

        public MainPage()
        {
            InitializeComponent();

            Navigate(typeof(View1));
        }

        private void Button1OnClicked(object sender, EventArgs e)
        {
            Navigate(typeof(View1));
        }

        private void Button2OnClicked(object sender, EventArgs e)
        {
            Navigate(typeof(View2));
        }

        // [NG version] Live Visual Tree leak
        public void Navigate(Type type)
        {
            var view = (View)Activator.CreateInstance(type);

            // Add new
            AbsoluteLayout.SetLayoutFlags(view, AbsoluteLayoutFlags.WidthProportional | AbsoluteLayoutFlags.HeightProportional);
            AbsoluteLayout.SetLayoutBounds(view, new Rectangle(0, 0, 1, 1));

            // Add new before remove old
            Container.Children.Add(view);

            // Remove old
            if (current != null)
            {
                Container.Children.Remove(current);
                Debug.WriteLine(Container.Children.Count);
            }

            current = view;
        }

        // [OK version]
        public void Navigate2(Type type)
        {
            var view = (View)Activator.CreateInstance(type);

            // Add new
            AbsoluteLayout.SetLayoutFlags(view, AbsoluteLayoutFlags.WidthProportional | AbsoluteLayoutFlags.HeightProportional);
            AbsoluteLayout.SetLayoutBounds(view, new Rectangle(0, 0, 1, 1));

            // Remove old
            if (current != null)
            {
                Container.Children.Remove(current);
                Debug.WriteLine(Container.Children.Count);
            }

            // Add new after remove old
            Container.Children.Add(view);

            current = view;
        }
    }
}
  • View1.xaml
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView
    x:Class="VisualTreeTest.View1"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    BackgroundColor="Blue" />
  • View2.xaml
<?xml version="1.0" encoding="UTF-8" ?>
<ContentView
    x:Class="VisualTreeTest.View2"
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    BackgroundColor="Red" />
  1. Press MainPage button and repeatedly add/remove view to AbsoluteLayout.Children will leak items on the Live Visual Tree, as shown in the screenshot.
  2. Navigate2() method instead of Navigate() method does not cause the problem

Expected Behavior

Items should also be removed from Live Visual Tree, regardless of the order of Add/Remove.

Actual Behavior

Depending on the order of Add/Remove, items on Live Visual Tree will leak.

Basic Information

  • Version with issue: 5.0.0.2012
  • Last known good version: N/A
  • Platform Target Frameworks:
    • Android: 11.0
  • Android Support Library / AndroidX Version:
  • Affected Devices: Emulator

Environment

Show/Hide Visual Studio info
Microsoft Visual Studio Enterprise 2019
Version 16.10.2
VisualStudio.16.Release/16.10.2+31410.357
Microsoft .NET Framework
Version 4.8.04084

インストールされているバージョン:Enterprise

Architecture Diagrams および Analysis Tools   00433-90100-48922-AA147
Microsoft Architecture Diagrams および Analysis Tools

Microsoft Visual Studio Tools for Applications 2019   00433-90100-48922-AA147
Microsoft Visual Studio Tools for Applications 2019

Visual C++ 2019   00433-90100-48922-AA147
Microsoft Visual C++ 2019

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

.NET Portability Analyzer   1.1.10808.0
Evaluates portability of assemblies across .NET platforms.

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

AnkhSVN2019   1.00.0.0012
AnkhSVN2019 - Subversion Support for Visual Studio

ASA Service Provider   1.0

ASP.NET and Web Tools 2019   16.10.526.50910
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   16.10.526.50910
詳細については、https://www.asp.net/ をご覧ください

Azure App Service Tools v3.0.0   16.10.526.50910
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

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

Azure Functions and Web Jobs Tools   16.10.526.50910
Azure Functions and Web Jobs Tools

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

Boost.Test のテスト アダプター   1.0
Boost.Test 向けに作成された単体テストを含む、Visual Studio のテスト ツールを有効にします。拡張機能のインストール ディレクトリに、使用条件およびサード パーティからの通知が含まれています。

Bundler & Minifier   2.8.396
Adds support for bundling and minifying JavaScript, CSS and HTML files in any project.

C# ツール   3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb
IDE で使用する C# コンポーネント。プロジェクトの種類や設定に応じて、異なるバージョンのコンパイラを使用できます。

Common Azure Tools   1.10
Azure Mobile Services および Microsoft Azure Tools で使用する共通サービスを提供します。

ConfigurationTransform   1.3
Automatically transform app.config during build process. Once the transformation is set, it will run on other build machines without the extension.

Cookiecutter   16.10.21111.19
cookiecutter 形式でテンプレートを検索、インスタンス化、カスタマイズするためのツールを提供します。

Dotfuscator Community Edition   6.3.0+8b29d6f4a2
PreEmptive Protection - Dotfuscator CE

EditorConfig Language Service   1.17.288
Language service for .editorconfig files.

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.

EnableHighlighting Extension   1.0
EnableHighlighting Visual Studio Extension Detailed Info

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
ファブリックの診断イベント

File Icons   2.7
Adds icons for files that are not recognized by Solution Explorer

File Nesting   2.6.85
Automatically nest files based on file name and enables developers to nest and unnest any file manually

Fix File Encoding   1.4.1
Prevents Visual Studio from adding BOM to UTF-8 files.

GitHub.VisualStudio   2.11.106.19330
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

GoToDnSpy   1.0
Open dnSpy or source.dot.net and select method or type under caret.

ILSpy.AddIn   1.0
Integration of the ILSpy Decompiler into Visual Studio.

Indent Guides   16
Indent Guides

Adds visual guides at each indentation level.

IntelliCode 拡張機能   1.0
IntelliCode Visual Studio 拡張機能の詳細情報

JetBrains ReSharper 2021.1.3   Build 211.0.20210525.202743
JetBrains ReSharper package for Microsoft Visual Studio. For more information about ReSharper, visit http://www.jetbrains.com/resharper. Copyright © 2021 JetBrains, Inc.

Linux コア ダンプ デバッグ   1.0.9.31313
Linux コア ダンプのデバッグを有効にします。

Markdown Editor   1.12.253
A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure HDInsight Azure Node   2.6.3000.0
HDInsight Node under Azure Node

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

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

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

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2019 - v2.9.40423.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Visual Studio IDE 内からの Azure DevOps パイプラインの構成を簡略化しています。

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

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

Microsoft Visual C++ ウィザード   1.0
Microsoft Visual C++ ウィザード

Microsoft Visual Studio Tools for Containers   1.2
ターゲット環境で ASP.NET Core アプリケーションを開発、実行、検証します。F5 キーを押してコンテナーで直接アプリケーションをデバッグ実行するか、Ctrl + F5 キーを押してコンテナーをリビルドせずにアプリを編集して更新します。

Microsoft Visual Studio VC パッケージ   1.0
Microsoft Visual Studio VC パッケージ

Mono Debugging for Visual Studio   16.10.15 (552afdf)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.30310.1 Commit Hash:e550dd1b679956810ccace4368dbc7a64443213b
Visual Studio での Node.js アプリケーション開発とデバッグのサポートを追加する

NuGet パッケージ マネージャー   5.10.0
Visual Studio 内の NuGet パッケージ マネージャー。NuGet の詳細については、https://docs.nuget.org/ にアクセスしてください

Office Developer Tools for Visual Studio   16.0.31130.00
Microsoft Office Developer Tools for Visual Studio

Open Command Line   2.4.236
2.4.236

OpenT4EditorSettingsCommand Extension   1.0
OpenT4EditorSettingsCommand Visual Studio Extension Detailed Info

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   16.10.21111.19
Python 開発者向けの IntelliSense、プロジェクト、テンプレート、デバッグ、インタラクティブ ウィンドウ、および他のサポートを提供します。

Python - Conda サポート   16.10.21111.19
Python プロジェクトの Conda サポート。

Python - Django サポート   16.10.21111.19
Django Web フレームワークに対してテンプレートと統合を提供します。

Python - プロファイル サポート   16.10.21111.19
Python プロジェクトのプロファイル サポート。

Razor (ASP.NET Core)   16.1.0.2122504+13c05c96ea6bdbe550bd88b0bf6cdddf8cde1725
Provides languages services for ASP.NET Core Razor.

ServiceStackVS   2.0.2
Templates and tools for use with the ServiceStack framework.

Solution Color Extension   1.0
Pick a different titlebar color depending on the current sln file you're working on.

SQL Server Analysis Services   15.0.19526.0
Microsoft SQL Server Analysis Services デザイナー 
Version 15.0.19526.0

SQL Server Data Tools   16.0.62105.04180
Microsoft SQL Server Data Tools

SQL Server Integration Services   15.0.2000.149
Microsoft SQL Server Integration Services デザイナー
バージョン 15.0.2000.149

SQL Server Reporting Services   15.0.19528.0
Microsoft SQL Server Reporting Services デザイナー 
Version 15.0.19528.0

SsmsVsIntegration   1.0
パッケージに関する情報

StylerPackage Extension   1.0
StylerPackage Visual Stuido Extension Detailed Info

Syntax Visualizer   1.0
An extension for visualizing Roslyn SyntaxTrees.

Test Adapter for Google Test   1.0
Google Test 向けに作成された単体テストを含む、Visual Studio のテスト ツールを有効にします。拡張機能のインストール ディレクトリに、使用条件およびサード パーティからの通知が含まれています。

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.30429.2002
TypeScript Tools for Microsoft Visual Studio

UnoPlatformPackage Extension   1.0
UnoPlatformPackage Visual Studio Extension Detailed Info

Visual Basic ツール   3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb
IDE で使用する Visual Basic コンポーネント。プロジェクトの種類や設定に応じて、異なるバージョンのコンパイラを使用できます。

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

Visual C++ for Linux Development   1.0.9.31313
Visual C++ for Linux Development

Visual F# Tools   16.10.0-beta.21262.7+1b23bbeda88ea3cb9be9af777f4c99fa8663df81
Microsoft Visual F# Tools

Visual Studio Code デバッグ アダプターのホスト パッケージ   1.0
Visual Studio Code デバッグ アダプターを 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

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

Visual Studio コンテナー ツール拡張機能   1.0
Visual Studio 内のコンテナーを表示、管理、診断します。

VisualStudio.DeviceLog   1.0
パッケージに関する情報

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

VSColorOutput   2.73
Color output for build and debug windows - https://mike-ward.net/vscoloroutput

Vue.js Pack 2019   1.2.3
Contains HTML Intellisense and code snippets for the Vue.js JavaScript library

Web Compiler   1.12.394
Compiler for LESS, Sass and CoffeeScript files

Windows Template Studio   3.9.20351.2
Windows Template Studio を使用して UWP アプリを簡単に構築します。ニーズを Windows 10 のパターンとベスト プラクティスに組み込むために、ウィザード ベースの UI を活用します。

Workflow Manager Tools 1.0   1.0
このパッケージには、Workflow Manager に必要な Visual Studio 統合コンポーネントが含まれています。

Xamarin   16.10.000.231 (d16-10@8111164)
Xamarin.iOS と Xamarin.Android の開発を有効にする Visual Studio 拡張機能

Xamarin Designer   16.10.0.115 (remotes/origin/c750fbf1bde3c720d077f51640fe197c6dac7cbe@c750fbf1b)
Visual Studio で Xamarin Designer ツールを有効にするための Visual Studio 拡張機能。

Xamarin Templates   16.10.5 (355b57a)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.3.0.4 (d16-10/ae14caf)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: b4a3858
    Java.Interop: xamarin/java.interop/d16-10@f39db25
    ProGuard: Guardsquare/proguard/v7.0.1@912d149
    SQLite: xamarin/sqlite/3.35.4@85460d3
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0


Xamarin.iOS and Xamarin.Mac SDK   14.20.0.10 (0e35b2e0b)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

スナップショット デバッグ拡張機能   1.0
スナップショット デバッグ Visual Studio 拡張機能の詳細情報

プロジェクト   1.0
パッケージに関する情報

Screenshots

  • Navigate() method behavior (leak on Live Visual Tree)

Image1

  • Navigate2() method behavior (no leak)

Image2

Reproduction Link

VisualTreeTest.zip

Workaround

The order in which the Navigate2() methods are processed does not cause any problems.

@usausa usausa added s/unverified New report that has yet to be verified t/bug 🐛 labels Jun 27, 2021
@usausa usausa changed the title [Bug] Android - Live Visual Tree leak when View is removed from AbsoluteLayout.Children [Bug] [Android] - Live Visual Tree leak when View removed from AbsoluteLayout.Children Jun 27, 2021
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Sep 3, 2021
@jsuarezruiz jsuarezruiz moved this from New to Needs Estimate in Triage Oct 7, 2021
@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label Oct 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Triage
  
Needs Estimate
Development

No branches or pull requests

2 participants