//I/xNativeActivity(21471): \VrCubeWorld.AppThread.cs:71 mallinfo  total allocated space:  2 027 243 344
            //I/xNativeActivity(21471): \VrCubeWorld.AppThread.cs:72 mallinfo  total free  space:  70 957 232
            //I/xNativeActivity(21471): \VrApi.ovrMatrix4f.cs:343 out of heap? errno: 12 Out of memory
            //I/xNativeActivity(21471): \VrCubeWorld.AppThread.cs:71 mallinfo  total allocated space:  -2 080 212 552
            //I/xNativeActivity(21471): \VrCubeWorld.AppThread.cs:72 mallinfo  total free  space:  74 286 664


            //I/xNativeActivity(15462): \VrCubeWorld.AppThread.cs:90 mallinfo  total allocated space:  5 512 048
            //I/xNativeActivity(15462): \VrCubeWorld.AppThread.cs:91 mallinfo  total free  space:  13 362 320

            //I/xNativeActivity(18481): \VrCubeWorld.AppThread.cs:71 mallinfo  total allocated space:  -2083023504
            //I/xNativeActivity(18481): \VrCubeWorld.AppThread.cs:72 mallinfo  total free  space:  76 049 040

            // https://groups.google.com/forum/#!topic/android-ndk/lcnwzszrESo
            // http://stackoverflow.com/questions/30480007/is-using-largeheap-in-android-manifest-a-good-practice
            // https://developer.android.com/reference/android/app/ActivityManager.html#getLargeMemoryClass()
            // http://dwij.co.in/increase-heap-size-of-android-application/
            // http://stackoverflow.com/questions/16957805/android-how-to-increase-application-memory-using-ndk


            // called by onCreate
            public ovrAppThread(JNIEnv env, jobject activityObject)
            {
                // 1907
                ConsoleExtensions.trace("enter ovrAppThread, call pthread_create");

                // why keep it?
                env.GetJavaVM(env, out this.JavaVm);
                this.ActivityObject = env.NewGlobalRef(env, activityObject);


                this.Thread = new System.Threading.Thread(
                    delegate()
                {
                    // can we do closures?
                    ConsoleExtensions.trace("enter thread for vrapi_SubmitFrame");


                    //malloc_h.malloc_stats();

                    //xmallinfo();

                    //ConsoleExtensions.trace("adding memory pressure...");

                    //var mb = 8 * 1024 * 1024;
                    //var pressure = new byte[mb];

                    ////System.Threading.Thread.Sleep(1000);

                    //xmallinfo();


                    ////ConsoleExtensions.trace("adding memory pressure... store...");

                    ////for (int i = 0; i < mb; i++)
                    ////{
                    ////    pressure[i] = (byte)(0xcc ^ i);
                    ////}

                    ////xmallinfo();

                    //// GC. would jsc static analysis know it means we can free that memory?

                    //stdlib_h.free(pressure);

                    ////pressure = null;

                    ////System.Threading.Thread.Sleep(1000);
                    //xmallinfo();


                    // would our chrome app be able to switch over to ndk over udp?
                    this.AppThreadFunction();
                }
                    );
                this.Thread.Start();
            }
            // called by onCreate
            public ovrAppThread(JNIEnv env, jobject activityObject)
            {
                // 1907
                ConsoleExtensions.trace("enter ovrAppThread, call pthread_create");

                env.GetJavaVM(env, out this.JavaVm);
                this.ActivityObject = env.NewGlobalRef(env, activityObject);

                var createErr = pthread.pthread_create(out this.Thread, null, AppThreadFunction, this);
                // tail call?
            }