Esempio n. 1
0
        internal bool _OnNativeGCRequested() // WARNING: The worker thread may trigger a V8 GC callback in its own thread!
        {
            using (Engine._ObjectsLocker.WriteLock())
            {
                if (Template is FunctionTemplate)
                {
                    ((FunctionTemplate)Template)._RemoveFunctionType(ID); // (make sure to remove the function references from the template instance)
                }
                Dispose();                                                // (notify any custom dispose methods to clean up)

                GC.SuppressFinalize(this);                                // (required otherwise the object's finalizer will be triggered again)

                _Handle.Dispose();                                        // (note: this may already be disposed, in which case this call does nothing)

                Engine._ClearAccessors(_ID.Value);                        // (just to be sure - accessors are no longer needed once the native handle is GC'd)

                if (_ID != null)
                {
                    _Engine._RemoveObjectWeakReference(_ID.Value);
                }

                _Handle.ObjectID = -1;

                Template = null; // (note: this decrements a template counter; allows the GC finalizer to collect the object)
                _ID      = null; // (also allows the GC finalizer to collect the object)
            }

            return(true); // ("true" means to "continue disposal of native handle" [if not already empty])
        }
Esempio n. 2
0
 protected virtual void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         pinnedHandle.Dispose();
         disposedValue = true;
     }
 }