Beispiel #1
0
        internal static void Dispose(IJavaPeerable instance, ref IntPtr handle, IntPtr key_handle, JObjectRefType handle_type)
        {
            if (handle == IntPtr.Zero)
            {
                return;
            }

            if (Logger.LogGlobalRef)
            {
                JNIEnv._monodroid_gref_log(
                    string.Format("Disposing handle 0x{0}\n", handle.ToString("x")));
            }

            JNIEnv.AndroidValueManager.RemovePeer(instance, key_handle);

            switch (handle_type)
            {
            case JObjectRefType.Global:
                lock (instance) {
                    JNIEnv.DeleteGlobalRef(handle);
                    handle = IntPtr.Zero;
                }
                break;

            case JObjectRefType.WeakGlobal:
                lock (instance) {
                    JNIEnv.DeleteWeakGlobalRef(handle);
                    handle = IntPtr.Zero;
                }
                break;

            default:
                throw new InvalidOperationException("Trying to dispose handle of type '" +
                                                    handle_type + "' which is not supported.");
            }
        }