Quantcast

JNI ERROR (app bug): local reference table overflow (max=512)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

JNI ERROR (app bug): local reference table overflow (max=512)

Christian

Hi,

 

in our application a service and an activity communicate through the message-handler pattern (http://developer.android.com/reference/android/app/Service.html#RemoteMessengerServiceSample)

 

On some devices with certain configuration (OS version/Mono version/target API) the app runs for days. However, on some, I get the following exception after one to several hours.

Am I missing a dispose? Could this be a bug within monodroid?

 

08-14 09:19:01.236: D/STATUSBAR-NetworkController(1976): onSignalStrengthsChanged signalStrength=SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 3 level=3

08-14 09:19:01.696: E/dalvikvm(10409): JNI ERROR (app bug): local reference table overflow (max=512)

08-14 09:19:01.696: W/dalvikvm(10409): JNI local reference table (0x648a78) dump:

08-14 09:19:01.696: W/dalvikvm(10409):   Last 10 entries (of 512):

08-14 09:19:01.696: W/dalvikvm(10409):       511: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       510: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       509: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       508: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       507: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       506: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       505: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       504: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       503: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):       502: 0x418d2058 android.os.Messenger

08-14 09:19:01.696: W/dalvikvm(10409):   Summary:

08-14 09:19:01.696: W/dalvikvm(10409):       512 of android.os.Messenger (1 unique instances)

08-14 09:19:01.696: E/dalvikvm(10409): Failed adding to JNI local ref table (has 512 entries)

08-14 09:19:01.696: I/dalvikvm(10409): "Thread-710" prio=5 tid=23 RUNNABLE

08-14 09:19:01.701: I/dalvikvm(10409):   | group="main" sCount=0 dsCount=0 obj=0x418d2480 self=0x58cf30

08-14 09:19:01.701: I/dalvikvm(10409):   | sysTid=10463 nice=0 sched=0/0 cgrp=default handle=5717544

08-14 09:19:01.711: I/dalvikvm(10409):   | schedstat=( 2479716412 1912016343 6855 ) utm=200 stm=47 core=0

08-14 09:19:01.711: I/dalvikvm(10409):   at android.os.SystemClock.uptimeMillis(Native Method)

08-14 09:19:01.711: I/dalvikvm(10409):   at android.os.Handler.sendMessageDelayed(Handler.java:446)

08-14 09:19:01.711: I/dalvikvm(10409):   at android.os.Handler.sendMessage(Handler.java:383)

08-14 09:19:01.711: I/dalvikvm(10409):   at android.os.Handler$MessengerImpl.send(Handler.java:587)

08-14 09:19:01.711: I/dalvikvm(10409):   at android.os.Messenger.send(Messenger.java:50)

08-14 09:19:01.711: I/dalvikvm(10409):   at dalvik.system.NativeStart.run(Native Method)

08-14 09:19:01.711: E/dalvikvm(10409): VM aborting

08-14 09:19:01.711: I/mono(10409): Stacktrace:

08-14 09:19:01.711: I/mono(10409):   at (wrapper delegate-invoke) <Module>.invoke_void__this___intptr_intptr_intptr_JValue[] (intptr,intptr,intptr,Android.Runtime.JValue[]) <0xffffffff>

08-14 09:19:01.711: I/mono(10409):   at Android.Runtime.JNIEnv.CallVoidMethod (intptr,intptr,Android.Runtime.JValue[]) <0x00053>

08-14 09:19:01.711: I/mono(10409):   at Android.OS.Messenger.Send (Android.OS.Message) <0x00103>

08-14 09:19:01.711: I/mono(10409):   at initions.OPHEOMOBILE.Core.OPHEOCoreService/CoreAccessHandler.execute (initions.oM3.Common.Enumerations.GUICommand,int) <0x002d3>

08-14 09:19:01.711: I/mono(10409):   at initions.OpheoMobile3.App.Controller.SetDisplayBrightness (int) <0x00053>

08-14 09:19:01.711: I/mono(10409):   at initions.opheoMobile3.ControllerBase.HandleDisplayBrightness () <0x0006f>

08-14 09:19:01.711: I/mono(10409):   at initions.opheoMobile3.ControllerBase.DoWork () <0x0001f>

08-14 09:19:01.711: I/mono(10409):   at initions.opheoMobile3.ControllerBase.WorkerThread () <0x0001f>

08-14 09:19:01.711: I/mono(10409):   at System.Threading.Thread.StartInternal () <0x0007f>

08-14 09:19:01.711: I/mono(10409):   at (wrapper runtime-invoke) object.runtime_invoke_void__this__ (object,intptr,intptr,intptr) <0xffffffff>

08-14 09:19:01.721: E/dalvikvm(10409): JNI ERROR (app bug): local reference table overflow (max=512)

08-14 09:19:01.721: W/dalvikvm(10409): JNI local reference table (0x648a78) dump:

08-14 09:19:01.721: W/dalvikvm(10409):   Last 10 entries (of 512):

08-14 09:19:01.721: W/dalvikvm(10409):       511: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       510: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       509: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       508: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       507: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       506: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       505: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       504: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       503: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):       502: 0x418d2058 android.os.Messenger

08-14 09:19:01.721: W/dalvikvm(10409):   Summary:

08-14 09:19:01.721: W/dalvikvm(10409):       512 of android.os.Messenger (1 unique instances)

08-14 09:19:01.721: E/dalvikvm(10409): Failed adding to JNI local ref table (has 512 entries)

08-14 09:19:01.721: I/dalvikvm(10409): "Thread-710" prio=5 tid=23 RUNNABLE

08-14 09:19:01.721: I/dalvikvm(10409):   | group="main" sCount=0 dsCount=0 obj=0x418d2480 self=0x58cf30

08-14 09:19:01.721: I/dalvikvm(10409):   | sysTid=10463 nice=0 sched=0/0 cgrp=default handle=5717544

08-14 09:19:01.721: I/dalvikvm(10409):   | schedstat=( 2488501620 1912016343 6855 ) utm=202 stm=47 core=0

08-14 09:19:01.721: I/dalvikvm(10409):   at android.os.SystemClock.uptimeMillis(Native Method)

08-14 09:19:01.721: I/dalvikvm(10409):   at android.os.Handler.sendMessageDelayed(Handler.java:446)

08-14 09:19:01.721: I/dalvikvm(10409):   at android.os.Handler.sendMessage(Handler.java:383)

08-14 09:19:01.721: I/dalvikvm(10409):   at android.os.Handler$MessengerImpl.send(Handler.java:587)

08-14 09:19:01.721: I/dalvikvm(10409):   at android.os.Messenger.send(Messenger.java:50)

08-14 09:19:01.721: I/dalvikvm(10409):   at dalvik.system.NativeStart.run(Native Method)

08-14 09:19:01.721: E/dalvikvm(10409): VM aborting

 

 

Regards

Christian

 


_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JNI ERROR (app bug): local reference table overflow (max=512)

Jonathan Pryor-2
On Aug 14, 2012, at 4:09 AM, "Breyer, Christian" <[hidden email]> wrote:
> On some devices with certain configuration (OS version/Mono version/target API) the app runs for days. However, on some, I get the following exception after one to several hours.
> Am I missing a dispose? Could this be a bug within monodroid?

Maybe.

Are you using JNIEnv anywhere within your app? If you're creating object instances (JNIEnv.NewObject()) or calling methods which return local references (JNIEnv.GetObjectField(), JNIEnv.CallObjectMethod(), JNIEnv.CallStaticObjectMethod(), etc.), you must either call JNIEnv.DeleteLocalRef() to destroy the local reference or pass the value to e.g. Java.Lang.Object.GetObject<T>(IntPtr, JniHandleOwnership) with JniHandleOwnership.TransferLocalRef:

        https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/Hello.cs#L630

If you're not directly using JNIEnv, then it could possibly be a bug on Mono for Android. I would appreciate any test case...

As a verification, you can enable lref logging, which will them spam logcat whenever a local reference is created or destroyed:

        adb shell setprop debug.mono.log lref

If you see a constantly increasing lref value, something is going wrong somewhere.

(Though I have noted that lref logging is flaky, and occasionally gives negative values...  Use as a guideline for now.)

> 08-14 09:19:01.236: D/STATUSBAR-NetworkController(1976): onSignalStrengthsChanged signalStrength=SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 3 level=3
> 08-14 09:19:01.696: E/dalvikvm(10409): JNI ERROR (app bug): local reference table overflow (max=512)
> 08-14 09:19:01.696: W/dalvikvm(10409): JNI local reference table (0x648a78) dump:
> 08-14 09:19:01.696: W/dalvikvm(10409):   Last 10 entries (of 512):
> 08-14 09:19:01.696: W/dalvikvm(10409):       511: 0x418d2058 android.os.Messenger
> 08-14 09:19:01.696: W/dalvikvm(10409):       510: 0x418d2058 android.os.Messenger

Apparently lots of android.os.Messenger instances are being created and not destroyed. I would suggest looking through your sources for "android/os/Messenger" (for JNIEnv use) or looking through the lref logging output for messages containing Android.OS.Messenger.

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JNI ERROR (app bug): local reference tableoverflow (max=512)

Christian
Thanks for your answer. The lref option really helped.

One thing causing a problem is to set the ReplyTo property in a message. The Messenger lref never gets destroyed, even though the message is.

                    Message oSendMessage = Message.Obtain(null, (int)eCommand);
                            oSendMessage.Data = oBundle as Bundle;
                            oSendMessage.ReplyTo = oClient;
                            oClient.Send(oSendMessage);

No matter what, this code - the third line to be precise - doesn't make sense anyway. By removing that line, no messenger get stuck in the lref table anymore.

But I can still see the lref count increasing. It seems odd what the trace is saying. It shows -l-, which I assume stands for lref destruction, but increases the lref count.
No filter active and nothing cut out.  Is there something happening the trace doesn't show or is it just a bug? This pattern continues throughout the trace.

08-14 19:35:22.915: I/monodroid-lref(6669): +l+ lrefc -13 handle 0xf0b0002d/L from    at Android.Runtime.JNIEnv.CallObjectMethod(IntPtr jobject, IntPtr jmethod)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Interop.TypeManager.GetClassName(IntPtr class_ptr)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, System.Type targetType)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, System.Type type)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object._GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Android.Graphics.Typeface.Create(System.String familyName, TypefaceStyle style)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x, Int32 y, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.915: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyb
08-14 19:35:22.915: I/monodroid-lref(6669): -l- lrefc -14 handle 0xf0b0002d/L from    at Android.Runtime.JNIEnv.DeleteRef(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Android.Runtime.JNIEnv.GetString(IntPtr value, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Interop.TypeManager.GetClassName(IntPtr class_ptr)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, System.Type targetType)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, System.Type type)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object._GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Android.Graphics.Typeface.Create(System.String familyName, TypefaceStyle style)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x,
08-14 19:35:22.915: I/monodroid-lref(6669): -l- lrefc -15 handle 0xa2700029/L from    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, System.Type targetType)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, System.Type type)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object._GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.915: I/monodroid-lref(6669):    at Android.Graphics.Typeface.Create(System.String familyName, TypefaceStyle style)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.915: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x, Int32 y, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.915: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.PaintGrid(System.Drawing.Graphics gx)
08-14 19:35:22.915: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.DrawImage(System.Drawing.Graphics gx)
08-14 19:35:22.915: I/monodroid-lref(6669):    at initions.oM3.
08-14 19:35:22.920: I/monodroid-lref(6669): -l- lrefc -16 handle 0x61e00025/L from    at Java.Lang.Object.RegisterInstance(IJavaObject instance, IntPtr value, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Lang.Object.SetHandle(IntPtr value, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Lang.Object..ctor(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Android.Graphics.Typeface..ctor(IntPtr javaReference, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Reflection.MonoCMethod.Invoke(System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Reflection.MonoCMethod.Invoke(BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Reflection.ConstructorInfo.Invoke(System.Object[] parameters)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Interop.TypeManager.CreateProxy(System.Type type, IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, System.Typ
08-14 19:35:22.920: I/monodroid-lref(6669): -l- lrefc -17 handle 0x8d300021/L from    at Android.Graphics.Typeface.Create(System.String familyName, TypefaceStyle style)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x, Int32 y, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.PaintGrid(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.DrawImage(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.MainView.OnDraw(Android.Graphics.Canvas canvas)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Android.Views.View.n_OnDraw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_canvas)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Object.d102a550-f71a-4ff5-af48-efd8bdfd4515(IntPtr , IntPtr , IntPtr )
08-14 19:35:22.920: I/monodroid-lref(6669): +l+ lrefc -16 handle 0x8d500021/L from    at Android.Runtime.JNIEnv.CallObjectMethod(IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Android.Graphics.Paint.SetTypeface(Android.Graphics.Typeface typeface)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x, Int32 y, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.PaintGrid(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.DrawImage(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.MainView.OnDraw(Android.Graphics.Canvas canvas)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Android.Views.View.n_OnDraw_Landroid_graphics_Canvas_(IntPtr jnienv, IntPtr native__this, IntPtr native_canvas)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Object.d102a550-f71a-4ff5-af48-efd8bdfd4515(IntPtr , IntPtr , IntPtr )
08-14 19:35:22.920: I/monodroid-lref(6669): -l- lrefc -17 handle 0x8d500021/L from    at Android.Runtime.JNIEnv.DeleteRef(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer, System.Type type)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Lang.Object._GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Java.Lang.Object.GetObject(IntPtr handle, JniHandleOwnership transfer)
08-14 19:35:22.920: I/monodroid-lref(6669):    at Android.Graphics.Paint.SetTypeface(Android.Graphics.Typeface typeface)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawStringInt(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Rectangle rect, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at System.Drawing.Graphics.DrawString(System.String text, System.Drawing.Font font, System.Drawing.Brush textBrush, Int32 x, Int32 y, System.Drawing.StringFormat stringFormat)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.PaintGrid(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.ExtendedKeyboard.DrawImage(System.Drawing.Graphics gx)
08-14 19:35:22.920: I/monodroid-lref(6669):    at initions.oM3.GUI.MainView.OnDraw(Android.Graphics.Can



If this is not enough information, I will try to send you a sample application tomorrow (GMT+1)

Regards
Christian

-----Urspr√ľngliche Nachricht-----
Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Jonathan Pryor
Gesendet: Dienstag, 14. August 2012 17:07
An: Discussions related to Mono for Android
Betreff: Re: [mono-android] JNI ERROR (app bug): local reference tableoverflow (max=512)

On Aug 14, 2012, at 4:09 AM, "Breyer, Christian" <[hidden email]> wrote:
> On some devices with certain configuration (OS version/Mono version/target API) the app runs for days. However, on some, I get the following exception after one to several hours.
> Am I missing a dispose? Could this be a bug within monodroid?

Maybe.

Are you using JNIEnv anywhere within your app? If you're creating object instances (JNIEnv.NewObject()) or calling methods which return local references (JNIEnv.GetObjectField(), JNIEnv.CallObjectMethod(), JNIEnv.CallStaticObjectMethod(), etc.), you must either call JNIEnv.DeleteLocalRef() to destroy the local reference or pass the value to e.g. Java.Lang.Object.GetObject<T>(IntPtr, JniHandleOwnership) with JniHandleOwnership.TransferLocalRef:

        https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/Hello.cs#L630

If you're not directly using JNIEnv, then it could possibly be a bug on Mono for Android. I would appreciate any test case...

As a verification, you can enable lref logging, which will them spam logcat whenever a local reference is created or destroyed:

        adb shell setprop debug.mono.log lref

If you see a constantly increasing lref value, something is going wrong somewhere.

(Though I have noted that lref logging is flaky, and occasionally gives negative values...  Use as a guideline for now.)

> 08-14 09:19:01.236: D/STATUSBAR-NetworkController(1976): onSignalStrengthsChanged signalStrength=SignalStrength: 99 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 gsm|lte 3 level=3
> 08-14 09:19:01.696: E/dalvikvm(10409): JNI ERROR (app bug): local reference table overflow (max=512)
> 08-14 09:19:01.696: W/dalvikvm(10409): JNI local reference table (0x648a78) dump:
> 08-14 09:19:01.696: W/dalvikvm(10409):   Last 10 entries (of 512):
> 08-14 09:19:01.696: W/dalvikvm(10409):       511: 0x418d2058 android.os.Messenger
> 08-14 09:19:01.696: W/dalvikvm(10409):       510: 0x418d2058 android.os.Messenger

Apparently lots of android.os.Messenger instances are being created and not destroyed. I would suggest looking through your sources for "android/os/Messenger" (for JNIEnv use) or looking through the lref logging output for messages containing Android.OS.Messenger.

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: JNI ERROR (app bug): local reference tableoverflow (max=512)

Jonathan Pryor-2
On Aug 14, 2012, at 2:06 PM, "Breyer, Christian" <[hidden email]> wrote:

> Thanks for your answer. The lref option really helped.
>
> One thing causing a problem is to set the ReplyTo property in a message. The Messenger lref never gets destroyed, even though the message is.
>
>            Message oSendMessage = Message.Obtain(null, (int)eCommand);
>                            oSendMessage.Data = oBundle as Bundle;
>                            oSendMessage.ReplyTo = oClient;
>                            oClient.Send(oSendMessage);
>
> No matter what, this code - the third line to be precise - doesn't make sense anyway. By removing that line, no messenger get stuck in the lref table anymore.

it's a bug in the generator: we allocate an lref but don't free it. (Argh!)

        [Register ("replyTo")]
        public Android.OS.Messenger ReplyTo {
                get { /* ... */ }
                set {
                        if (replyTo_jfieldId == IntPtr.Zero)
                                replyTo_jfieldId = JNIEnv.GetFieldID (class_ref, "replyTo", "Landroid/os/Messenger;");
                        JNIEnv.SetField (Handle, replyTo_jfieldId, JNIEnv.ToLocalJniHandle (value));
                }
        }

JNIEnv.ToLocalJniHandle() allocates a local ref, but it's never freed. Looks like I forgot to check field generation 4 months ago...

This has been filed as:

        https://bugzilla.xamarin.com/show_bug.cgi?id=6531

So there are two "workarounds":

(1) Don't Do that (bwa-ha-ha-ha-ha)
(2) "Somehow" ensure that the thread setting the Messenger.ReplyTo property eventually "returns to Java." All threads created by Dalvik that enter managed code should eventually return to Java code, e.g. the Main thread which invokes Activity.OnCreate(). Once Activity.OnCreate() completes, execution will return to the Java thread. Upon returning to Java code from non-Java code, the local reference table is cleared.

Unfortunately this won't do you any good for threads created by Mono (System.Threading.Thread, ThreadPool, etc.), as they'll never "return" to Java.

> But I can still see the lref count increasing. It seems odd what the trace is saying. It shows -l-, which I assume stands for lref destruction, but increases the lref count.

> 08-14 19:35:22.915: I/monodroid-lref(6669): -l- lrefc -14 handle 0xf0b0002d/L from    at Android.Runtime.JNIEnv.DeleteRef(IntPtr handle, JniHandleOwnership transfer)
...
> 08-14 19:35:22.915: I/monodroid-lref(6669): -l- lrefc -15 handle 0xa2700029/L from    at Java.Interop.TypeManager.CreateInstance(IntPtr handle, JniHandleOwnership transfer, System.Type targetType)

Look carefully: the count is _negative_, and decrements from -14 to -15. As I said, lref counting is rather flaky at the moment...

Thanks,
 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Loading...