Search code examples
androidxamarinlogcat

How to output full global reference log for android app with XAMARIN


I'm trying to detect leaking to release global reference in my android app.
I see in the troubleshooting guide of XAMARIN it shows very detail about log of global reference.
URL: https://developer.xamarin.com/guides/android/troubleshooting/troubleshooting/#Global_Reference_Messages
It shows which object create global reference such as:

I/monodroid-gref(12405): +g+ grefc 108 gwrefc 0 obj-handle 0x40517468/L -> new-handle 0x40517468/L from    at Java.Lang.Object.RegisterInstance(IJavaObject instance, IntPtr value, JniHandleOwnership transfer)
I/monodroid-gref(12405):    at Java.Lang.Object.SetHandle(IntPtr value, JniHandleOwnership transfer)
I/monodroid-gref(12405):    at Java.Lang.Object..ctor(IntPtr handle, JniHandleOwnership transfer)
I/monodroid-gref(12405):    at Java.Lang.Thread+RunnableImplementor..ctor(System.Action handler, Boolean removable)
I/monodroid-gref(12405):    at Java.Lang.Thread+RunnableImplementor..ctor(System.Action handler)
I/monodroid-gref(12405):    at Android.App.Activity.RunOnUiThread(System.Action action)
I/monodroid-gref(12405):    at Mono.Samples.Hello.HelloActivity.UseLotsOfMemory(Android.Widget.TextView textview)
I/monodroid-gref(12405):    at Mono.Samples.Hello.HelloActivity.m__3(System.Object o)

--> We can see "at Java.Lang.Object.RegisterInstance" created global reference.
But actually I only see count ,handle address information in the logcat as below:

06-10 14:55:06.225 I/monodroid-gref(19580): +g+ grefc 926 gwrefc 0 obj-handle 0x19/I -> new-handle 0x101682/G from thread '(null)'(1)
06-10 14:55:06.238 I/monodroid-gref(19580): +g+ grefc 927 gwrefc 0 obj-handle 0x5/I -> new-handle 0x10167e/G from thread 'Threadpool worker'(57)
06-10 14:55:06.261 I/monodroid-gref(19580): -g- grefc 927 gwrefc 0 handle 0x10167e/G from thread 'Threadpool worker'(57)
06-10 14:55:06.286 I/monodroid-gref(19580): +g+ grefc 927 gwrefc 0 obj-handle 0x19/I -> new-handle 0x201686/G from thread '(null)'(1)
06-10 14:55:06.288 I/monodroid-gref(19580): +g+ grefc 928 gwrefc 0 obj-handle 0x1/I -> new-handle 0x20167e/G from thread 'Threadpool worker'(57)
06-10 14:55:06.295 I/monodroid-gref(19580): +g+ grefc 929 gwrefc 0 obj-handle 0x200019/I -> new-handle 0x10168a/G from thread '(null)'(1)
06-10 14:55:06.306 I/monodroid-gref(19580): -g- grefc 929 gwrefc 0 handle 0x1676/G from thread 'Threadpool worker'(57)
06-10 14:55:06.351 I/monodroid-gref(19580): +g+ grefc 929 gwrefc 0 obj-handle 0x200019/I -> new-handle 0x101676/G from thread '(null)'(1)
06-10 14:55:06.357 I/monodroid-gref(19580): +g+ grefc 930 gwrefc 0 obj-handle 0x100019/I -> new-handle 0x10168e/G from thread '(null)'(1)

Do I missed any setting? Please help!


Solution

  • I found the solution here: https://developer.xamarin.com/releases/android/xamarin.android_5/xamarin.android_5.1/#GREF_Logging_Changes

    (But I'm using Samsung S6, so run-as command doesn't work :()