Bug 18641 - memory leaks if OnTextChenge override in TextView
Summary: memory leaks if OnTextChenge override in TextView
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.13.x
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2014-03-29 09:51 UTC by Andrey Mazurov
Modified: 2014-04-10 23:58 UTC (History)
2 users (show)

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

test project (16.25 KB, application/zip)
2014-03-29 09:51 UTC, Andrey Mazurov

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 Andrey Mazurov 2014-03-29 09:51:05 UTC
Created attachment 6433 [details]
test project

if override OnTextChanged in TextView class then will you have memory leaks.
For check you need turn device and push button.
Comment 1 Udham Singh 2014-03-31 10:36:22 UTC
I have checked this issue with the sample project attached into the bug description, As per my observation we are getting almost same behavior if we run the application with or without overriding the "OnTextChanged" method. And also I have noticed that we are getting the difference of same no. of bytes allocated by managed memory after 4th and 5th click is 176, around > 2000 bytes after 3rd and 4th click.

Screencast : 

With overriding the OnTextChanged method : http://screencast.com/t/HMMcsVCx
Without overriding the OnTextChanged method : http://screencast.com/t/8cpijjM5AT

Environment Info:

=== Xamarin Studio ===

Version 4.2.3 (build 60)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
	Mono 3.2.6 ((no/9b58377)
	GTK+ 2.24.23 theme: Raleigh
	GTK# (
	Package version: 302060000

=== Apple Developer Tools ===

Xcode 5.1 (5035)
Build 5B45j

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 58c3efa
Build date: 2014-10-03 18:02:26-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Xamarin.Android ===

Version: 4.12.1 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Build Information ===

Release ID: 402030060
Git revision: 30c4afc300c2a39ec5300851357ce02e49dd217e
Build date: 2014-03-05 22:09:33+0000
Xamarin addins: f8a9589b57c2bfab2ccd73c880e7ad81e3ecf044

=== Operating System ===

Mac OS X 10.9.2
Darwin MacMini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

Please provide your some valuable input on the same, so that I can confirm the same issue.
Comment 3 Andrey Mazurov 2014-04-04 12:53:29 UTC
you must look in next values in Log after turn device.
Memory leaks exist if you turn device.

GC_BRIDGE num-objects 3 num_hash_entries 3
Comment 4 Udham Singh 2014-04-07 06:09:41 UTC
I have checked this issue with test project attached into bug description. As per my observation I have noticed that we are getting "GC_BRIDGE num-objects 3 num_hash_entries 3" into "Application output" when click on "Hello Word, Click Me!" button as it is mentioned into comment 2 and 3.

Screencast : http://screencast.com/t/gIXc1IaOkz

Application Output : https://gist.github.com/anonymous/87fb5782b532a6d95cf2

Environment Info:

Mac OS X 10.9.2
Xamarin Studio : 4.2.3 (build 60)
Xamarin.Android : 4.12.1 (Starter Edition)
Comment 5 Andrey Mazurov 2014-04-07 06:19:26 UTC
You didn't get it. You should rotate device several times to switch UI from Portrait to Landscape mode to get memory leak.

PS: turn verb
1 the wheels were still turning: go round, revolve, rotate, spin, go round and round, go round in circles, roll, circle, wheel, whirl, twirl, gyrate, swivel, spiral, pivot.
2 I turned and headed back the way I had come: change direction, turn round, change course, make a U-turn, reverse direction; swing round, wheel round, turn about.
Comment 6 Jonathan Pryor 2014-04-10 16:01:48 UTC
There is a leak.

Enable GREF logging:

    adb shell setprop debug.mono.log gref,gc

Restart the app, and note the current GREF value:

> I/monodroid-gref( 4819): +g+ grefc 13 gwrefc 0 obj-handle 0x750001d/L -> new-handle 0x10047e/G from    at Android.Runtime.JNIEnv.NewGlobalRef(IntPtr jobject)

Rotate the device a few times (e.g. 10), and the GREF count steadily increases. This is expected.

> I/monodroid-gref( 4819): +g+ grefc 83 gwrefc 0 obj-handle 0x32c0001d/L -> new-handle 0x2005ce/G from    at Android.Runtime.JNIEnv.NewGlobalRef(IntPtr jobject)

Tap the button, and the GREF count decreases. Keep tapping the button until the gref count stops decreasing.

What _should_ happen is that you get back to the original GREF count, i.e. 13.

What _actually_ happens is you don't:

> I/monodroid-gref( 4819): -g- grefc 52 gwrefc 0 handle 0x210056a/G from    at Android.Runtime.JNIEnv.DeleteGlobalRef(IntPtr jobject)

52 is a far cry from 13, and implies that we've "lost" 39 GREFs across those 10 rotations.
Comment 7 Jonathan Pryor 2014-04-10 23:58:39 UTC
Fixed in monodroid/638860b9.

Thank you for the test case.