Bug 25592 - Memory Leak when using Custom Renderer in conjunction with RaiseChild/LowerChild
Summary: Memory Leak when using Custom Renderer in conjunction with RaiseChild/LowerChild
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.3.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-23 09:49 UTC by ron.jacobs@newellco.com
Modified: 2015-01-23 09:31 UTC (History)
6 users (show)

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


Attachments

Description ron.jacobs@newellco.com 2014-12-23 09:49:35 UTC
The basic premise is this:
                I have an Absolute layout that contains several of my custom controls.  When I click a button, some of the custom controls have their Z-order modified via RaiseChild/LowerChild.
When the Z-order is changed, my custom renderer has a call to my overwritten OnElementChanged method.  The NewValue is set to the control that has been modified, there is no call with a non-null value in the OldValue parameter.  
                After the call to modify the Z-order, I update a bindable value on my control.  Since additional calls to OnElementChanged have been made, the system thinks there are  more active custom controls than there really are, as  a result, I get too many calls to OnElementPropertyChanged.

                This behavior is identical on iOS and Android and can be easily seen in my sample application.  Click the “Raise Child” button several times, you will see the behavior in the debugger.


My sample code can be found here:
https://www.dropbox.com/s/n9898paq40phwy8/RaiseChildTest.zip?dl=0
Comment 1 Rajneesh Kumar 2014-12-30 01:11:35 UTC
I have checked this issue with following mentioned steps.

1. Open attached test case in VS.
2. Set android as start-up project.
3. Build and deploy it on emulator, deploy successfully.
4. Click on "Raise Child" button several times.
5. Observed the behavior in debug output window as below:

12-30 11:21:44.535 D/dalvikvm( 2749): GC_EXPLICIT freed 63K, 5% free 3404K/3576K, paused 42ms+0ms, total 127ms
12-30 11:21:44.539 D/Mono    ( 2749): GC_OLD_BRIDGE num-objects 9 num_hash_entries 10 sccs size 10 init 0.00ms df1 6.44ms sort 0.00ms dfs2 20.50ms setup-cb 0.00ms free-data 0.04ms links 1/1/1/1 dfs passes 20/11
12-30 11:21:44.539 D/Mono    ( 2749): GC_MINOR: (Nursery full) pause 93.84ms, total 101.75ms, bridge 149.49ms promoted 640K major 896K los 8K

Screencast: http://www.screencast.com/t/9vFoZf8sx1a

Please let me confirmed that this is the same issue experiencing you and I followed the correct steps to reproduce this issue/behavior, if No then please let me know that what steps is missing/wrong or should I follow to reproduce this issue ?

VS trace Logs: http://www.screencast.com/t/tWQjzCjCM
Application output: https://gist.github.com/Rajneesh360Logica/a550aeb24e7ffac1d8c5
adb logs: https://gist.github.com/Rajneesh360Logica/e5422db8f4b2a1c0e0ef

Please let me know if I am missing anything ?

Environment Info:

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0446016-02381
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0446016-02381
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0446016-02381
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446016-02381
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446016-02381
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446016-02381
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0446016-02381
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0446016-02381
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.3.50717.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.20703.0
For additional information, visit http://www.asp.net/

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

Microsoft Advertising SDK for Windows Phone   
Microsoft Advertising SDK for Windows Phone
Build 

Microsoft Azure Mobile Services Tools   1.2
Microsoft Azure Mobile Services Tools

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

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.2
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.30919.1
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

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

Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 ron.jacobs@newellco.com 2015-01-05 10:59:48 UTC
In the custom control renderer, put break points in the OnElementPropertyChanged method.  As you change the z-order you will see that there are WAY to many calls to this method.

If you put a break point in the OnElementChanged method, you will see that "The NewValue is set to the control that has been
modified, there is no call with a non-null value in the OldValue parameter." 

In other words, changing the Z-order causes an OnElementChanged event to occur, so the app thinks there are now many more box views visible than actually exist.
Comment 3 Cody Beyer (MSFT) 2015-01-06 23:59:48 UTC
I have observed this behavior in iOS and observed the memory rise with Instruments.
Comment 4 Jason Smith [MSFT] 2015-01-17 18:03:08 UTC
Should be fixed in 1.3.2-pre1
Comment 5 Rajneesh Kumar 2015-01-23 09:31:44 UTC
I have checked this issue with the following builds:

Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.50938
Xamarin   3.9.236.0 (d6a2cae)
Visual Studio extension to enable development for Xamarin.iOS and
Xamarin.Android.
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.
Xamarin.iOS   8.6.0.0 (eb24bdcf5cba2c12b673a07e0a8cce368b9563b3)
Visual Studio extension to enable development for Xamarin.iOS.
Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.Forms Version: 1.3.2.6299-pre1

I observed that this issue is working fine now, here is the screencast for the same: http://www.screencast.com/t/bm7jh6kH

This issue has been fixed, hence closing this issue.

Note You need to log in before you can comment on or make changes to this bug.