Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Last active July 6, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonpryor/3cb9902b9fa8c19324f8a0fedb3c1b8a to your computer and use it in GitHub Desktop.
Save jonpryor/3cb9902b9fa8c19324f8a0fedb3c1b8a to your computer and use it in GitHub Desktop.
--- MainActivity.cs.jonp-orig 2016-07-06 17:11:28.000000000 -0400
+++ MainActivity.cs 2016-07-06 17:21:21.000000000 -0400
@@ -3,7 +3,10 @@
using Android.OS;
using Android.Runtime;
+using Java.Interop;
+
using System;
+using System.Diagnostics;
using System.Threading;
namespace JNICrash
@@ -24,6 +27,12 @@
// and attach an event to it
Button button = FindViewById<Button>(Resource.Id.myButton);
+ var logCreateLocalRef = (Action<JniObjectReference>)
+ Delegate.CreateDelegate (
+ typeof (Action<JniObjectReference>),
+ typeof (JniEnvironment),
+ "LogCreateLocalRef");
+
button.Click += delegate
{
/*** LOOK HERE ***/
@@ -31,6 +40,7 @@
// Get off the main thread.
Thread thread = new Thread(() =>
{
+ var time = Stopwatch.StartNew();
// Perform the test 1024 times (greater than the
// size of the local reference table).
for (int i = 0; i < 1024; i++)
@@ -40,6 +50,7 @@
// The source for this method can be found in
// libdemo/src/demo_DemoLibrary.c.
IntPtr outputPtr = DemoLibrary.Java_demo_DemoLibrary_test(JNIEnv.Handle, IntPtr.Zero);
+ logCreateLocalRef(new JniObjectReference (outputPtr, JniObjectReferenceType.Local));
// Get the result of the method as a C# byte[].
// This worked in Xamarin.Android 5, but now floods the logs
@@ -52,6 +63,8 @@
// Update our counter.
Console.WriteLine("Called test() method {0} times (output length: {1} bytes).", count++, output.Length);
}
+ time.Stop();
+ Console.WriteLine("# jonp: Elapsed time: {0}ms", time.ElapsedMilliseconds);
})
{
IsBackground = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment