Example #1
0
        public void Destroy()
        {
            lock (this)
            {
                if (!_isValid)
                {
                    return;
                }
                _isValid = false;
                try
                {
                    OnDestroy?.Invoke(this);
                }
                catch (Exception e)
                {
                    _logger?.WriteException(e);
                }
            }

            _timerManager.Destroy();
            _objectCache.Destroy();
            _typeDB.Destroy();

            GC.Collect();
            GC.WaitForPendingFinalizers();
            ExecutePendingActions();

            // _rwlock.EnterWriteLock();
            for (int i = 0, count = _contextRefs.Count; i < count; i++)
            {
                var contextRef = _contextRefs[i];
                contextRef.target.Destroy();
            }

            _contextRefs.Clear();
            _mainContext = null;
            // _rwlock.ExitWriteLock();


            if (_asyncManager != null)
            {
                _asyncManager.Destroy();
                _asyncManager = null;
            }

            JSApi.JS_FreeRuntime(_rt);
            var id = _runtimeId;

            _runtimeId = -1;
            _rt        = JSRuntime.Null;

            try
            {
                OnAfterDestroy?.Invoke(id);
            }
            catch (Exception e)
            {
                _logger?.WriteException(e);
            }
        }
Example #2
0
        public void Destroy()
        {
            if (!_isValid)
            {
                return;
            }
            _isValid = false;

            try
            {
                OnDestroy?.Invoke(this);
            }
            catch (Exception e)
            {
                _runtime.GetLogger()?.WriteException(e);
            }
            _stringCache.Destroy();
            _atoms.Clear();

            JSApi.JS_FreeValue(_ctx, _numberConstructor);
            JSApi.JS_FreeValue(_ctx, _stringConstructor);
            JSApi.JS_FreeValue(_ctx, _functionConstructor);
            JSApi.JS_FreeValue(_ctx, _globalObject);
            JSApi.JS_FreeValue(_ctx, _operatorCreate);

            JSApi.JS_FreeValue(_ctx, _moduleCache);
            JSApi.JS_FreeValue(_ctx, _require);
            JSApi.JS_FreeContext(_ctx);
            var id = _contextId;

            _contextId = -1;

            if (_coroutines != null)
            {
                _coroutines.Destroy();
                _coroutines = null;
            }

            _ctx = JSContext.Null;
            try
            {
                OnAfterDestroy?.Invoke(id);
            }
            catch (Exception e)
            {
                _runtime.GetLogger()?.WriteException(e);
            }
        }
Example #3
0
        public void Destroy()
        {
            _isValid = false;
            try
            {
                OnDestroy?.Invoke(this);
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }

            _timerManager.Destroy();
            _objectCache.Clear();
            _typeDB.Destroy();
            GC.Collect();
            CollectPendingGarbage();

            for (int i = 0, count = _contexts.Count; i < count; i++)
            {
                var context = _contexts[i];
                context.Destroy();
            }

            _contexts.Clear();

            if (_container != null)
            {
                Object.DestroyImmediate(_container);
                _container = null;
            }

            JSApi.JS_FreeRuntime(_rt);
            _rt = JSRuntime.Null;

            try
            {
                OnAfterDestroy?.Invoke(this);
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
        }