DestroyV8EngineProxy() private method

private DestroyV8EngineProxy ( NativeV8EngineProxy engine ) : void
engine NativeV8EngineProxy
return void
示例#1
0
        public void Dispose()
        {
            if (_NativeV8EngineProxy != null)
            {
                _TerminateWorker(); // (will return only when it has successfully terminated)

                // ... clear all handles of object IDs for disposal ...

                HandleProxy *hProxy;

                for (var i = 0; i < _HandleProxies.Length; i++)
                {
                    hProxy = _HandleProxies[i];
                    if (hProxy != null && !hProxy->IsDisposed)
                    {
                        hProxy->_ObjectID = -2; // (note: this must be <= -2, otherwise the ID auto updates -1 to -2 to flag the ID as already processed)
                    }
                }

                // ... allow all objects to be finalized by the GC ...

                ObservableWeakReference <V8NativeObject> weakRef;

                for (var i = 0; i < _Objects.Count; i++)
                {
                    if ((weakRef = _Objects[i]) != null && weakRef.Object != null)
                    {
                        weakRef.Object._ID      = null;
                        weakRef.Object.Template = null;
                        weakRef.Object._Handle  = ObjectHandle.Empty;
                    }
                }

                // ... destroy the native engine ...

                if (_NativeV8EngineProxy != null)
                {
                    _Engines[_NativeV8EngineProxy->ID] = null; // (notifies any lingering handles that this engine is now gone)
                    V8NetProxy.DestroyV8EngineProxy(_NativeV8EngineProxy);
                    _NativeV8EngineProxy = null;
                }
            }
        }