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: monodroid-boun...@lists.ximian.com 
[mailto:monodroid-boun...@lists.ximian.com] 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" <bre...@initions.com> 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
Monodroid@lists.ximian.com

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



_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

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

Reply via email to