Don’t use anonymous functions, but global ones, then you can explicitly “remove_notifier” them.
Close the terminal, open it again (this recreates the terminal’s interpreter).
Delete the thing you are attached to (create new song, delete the track, device and so on).
Each tool (and the terminal, as said above) lives in a separate Lua interpreter.
Globals can not be shared between different interpreters, unless you use sockets or files or other related stuff.
Not in memory, but using the document option, you could share variable values through saved documents and set time-stamps on saved variables (The latter if you need some kind of check mark to figure out if variable values have been changed since the last time you loaded them).