__zigar.abandon() - chung-leong/zigar GitHub Wiki

Unload the module from memory. Afterward, imported functions will no longer work.

This function is meant mainly for use during automated testing, where a large number of modules would get loaded and be used only once.

const std = @import("std");

pub fn hello() void {
    std.debug.print("hello\n", .{});
}
import { __zigar, hello } from './special-exports-example-1.zig';
const { abandon } = __zigar;

hello();
abandon();
try {
    hello();
} catch (err) {
    console.log(err.message);
}
hello
Module was abandoned

Unloading does not happen immediately. This function merely removes all references to the module, allowing it to be garbage-collected. It can fail if there're objects allocated from the Zig memory heap sitting somewhere.


Special exports: __zigar