package forget

package forget removes the regisration information about a package that was supplied via package provide.

Synopsis

package forget ?package package ...?

Description

package forget does not "undo" what was done by the script evaluated in order to provide the package, which may be arbirarily complex. In the common case, the effect of loading a package is that a new namespace is created to hold the command and variables provided by the package. In this common case, follow up package forget with namespace delete to cleanly remove all vestiges of a package from an interpreter. A pure-Tcl package arrange for anything it loads to get unloaded when its namespace is deleted. Here is one way, provided by RS, to do that:

namespace eval ::foo {
    variable cleanup 0
 
    proc cleanup {} {
        # do cleanup
    }
    trace add variable ::foo::cleanup unset ::foo::cleanup
}

An extension can take advantage of the delete callback slot in Tcl_CreateObjCmd to do any cleanup, including unloading of any shared objects.

Page authors

PYK
RS
schlenk

AMB - 2023-09-22 14:15:36

The package Tin has a command "tin forget" that also deletes the corresponding namespace.