Beispiel #1
0
        ///// <summary>
        ///// Called when this handle has no more managed references, and the native garbage collector wants to collect this instance.
        ///// <para>Note: Handle disposal process only completes when there are no more managed references to the associated managed object as well.</para>
        ///// </summary>
        //??internal bool _OnNativeGCRequested()
        //{
        //    // ... the native V8 engine is requesting garbage collection ...
        //    var dispose = _IsDisposeReady;
        //    if (dispose && _ManagedObjectInfo != null)
        //        lock (_Engine._Objects)
        //        {
        //            _Engine._Objects.Remove(_ManagedObjectInfo._ID);
        //        }
        //    return dispose;
        //}

        ///// <summary>
        ///// If this is true, then the native handle was made weak, and this handle instance is pending disposal.
        ///// </summary>
        //??internal bool _NativeHandleIsWeak;

        //??internal void _MakeWeakNativeHandle()
        //{
        //    if (!_NativeHandleIsWeak)
        //    {
        //        V8NetProxy.MakeWeakHandle(_HandleProxy);
        //        _NativeHandleIsWeak = true;
        //    }
        //}

        //??internal void _MakeStrongNativeHandle()
        //{
        //    if (_NativeHandleIsWeak)
        //    {
        //        V8NetProxy.MakeStrongHandle(_HandleProxy);
        //        _NativeHandleIsWeak = false;
        //    }
        //}

        /// <summary>
        /// Completes the disposal of the native handle.
        /// <para>Note: A disposed native handle is simply cached for reuse, and always points back to the same managed handle.</para>
        /// </summary>
        internal void _ForceDisposal()
        {
            if (!_IsWeakManagedObject)
            {
                throw new InvalidOperationException("A managed object is still associated with this handle");
            }

            lock (this)
            {
                if (!IsDisposed)
                {
                    //??if (_NativeHandleIsWeak)
                    //    _MakeStrongNativeHandle(); // (prevent any GC callback just in case)

                    V8NetProxy.DisposeHandleProxy(_HandleProxy);
                    // (note: '_HandleProxy' is NOT set to null here because the connection has to be maintained for cache purposes)

                    GC.RemoveMemoryPressure((sizeof(HandleProxy) + sizeof(ValueProxy)));
                }

                if (_ManagedObjectInfo != null)
                {
                    _ManagedObjectInfo.Dispose();
                    _ManagedObjectInfo = null;
                    ManagedObjectID    = -1;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Resets the handle for reuse.
        /// </summary>
        /// <returns></returns>
        internal Handle _Reset()
        {
            _ManagedObjectInfo = null;
            //??_NativeHandleIsWeak = false;
            var owr = _Engine._Handles[_ID];

            if (owr != null)
            {
                lock (owr) // (only need to update this one instance)
                {
                    owr.Reset();
                }
            }

            GC.AddMemoryPressure((sizeof(HandleProxy) + sizeof(ValueProxy)));

            return(this);
        }