close method

void close()

Free Runtime and Context. After dispose, the engine cannot be reopened. After close without dispose, the next evaluate recreates the engine.

Implementation

void close() {
  try {
    releaseHostCaches();
  } catch (_) {}
  final rt = _rt;
  final ctx = _ctx;
  if (rt == null) return;
  String? referenceLeak;
  try {
    _executePendingJob();
  } catch (_) {}
  if (ctx != null) {
    final jsonStringifyFn = _jsonStringifyFn;
    _jsonStringifyFn = null;
    if (jsonStringifyFn != null) {
      try {
        jsFreeValue(ctx, jsonStringifyFn);
      } catch (_) {}
    }
    referenceLeak = jsReleaseRuntimeRefs(rt, ctx);
    try {
      jsFreeContext(ctx);
    } catch (_) {}
  }
  _rt = null;
  _ctx = null;
  localContext.clear();
  dartContext.clear();
  _needsInitialization = true;
  try {
    jsFreeRuntime(rt);
  } on String catch (e) {
    throw JSError(e);
  }
  if (referenceLeak != null) throw JSError(referenceLeak);
}