dispose method
Step #3 (retention) — releases the interpreter artifacts retained from the most recent run so a finished run's SCompilationUnit graph, interpreted declarations, and per-run environment become collectable while this runner is kept alive but idle.
Mirror of D4rt.dispose (analyzer twin). It addresses the baseline's
per-instance AST/BridgedClass retention: an embedder that keeps one
runner per script (the pattern behind the ~88 retained AST generations)
can call dispose after a run to drop that run's graph instead of pinning
it for the runner's whole lifetime. Reusing a single runner across scripts
is now cheap (step #2 shares the bridge surface process-wide) and is
preferred; dispose covers the per-instance case.
Releases per-run state only: script-declared environment entries and the
cross-build native accumulator (via resetScriptDeclarations), the
parsed-module cache (via AstModuleLoader.releaseLoadedModules), and the
InterpreterVisitor. Preserves the process-global pool, warm-parent cache,
and shared bridged-module env cache. A subsequent executeBundle rebuilds
the per-run loader/visitor, so dispose is non-destructive.
Implementation
void dispose() {
resetScriptDeclarations();
_lastModuleLoader?.releaseLoadedModules();
_lastModuleLoader = null;
_visitor = null;
}