SYNOPSIS
#include <tcl.h>
Tcl_Interp * Tcl_CreateInterp()
Tcl_DeleteInterp(interp)
int Tcl_InterpDeleted(interp)
ARGUMENTS
DESCRIPTION
INTERPRETERS AND MEMORY MANAGEMENT
The mechanism relies on matching up calls to
The rules for when the user of an interpreter must call
- Interpreters Passed As Arguments
-
Functions that are passed an interpreter as an argument can safely use the interpreter without any special protection. Thus, when you write an extension consisting of new Tcl commands, no special code is needed to protect interpreters received as arguments. This covers the majority of all uses.
- Interpreter Creation And Deletion
-
When a new interpreter is created and used in a call to
Tcl_Eval() ,Tcl_VarEval() ,Tcl_GlobalEval() ,Tcl_SetVar() , orTcl_GetVar() , a pair of calls toTcl_Preserve() andTcl_Release() should be wrapped around all uses of the interpreter. Remember that it is unsafe to use the interpreter onceTcl_Release() has been called. To ensure that the interpreter is properly deleted when it is no longer needed, callTcl_InterpDeleted() to test if some other code already calledTcl_DeleteInterp() ; if not, callTcl_DeleteInterp() before callingTcl_Release() in your own code. Do not callTcl_DeleteInterp() on an interpreter for whichTcl_InterpDeleted() returns nonzero. - Retrieving An Interpreter From A Data Structure
-
When an interpreter is retrieved from a data structure (for example, the client data of a callback) for use in
Tcl_Eval() ,Tcl_VarEval() ,Tcl_GlobalEval() ,Tcl_SetVar() , orTcl_GetVar() , a pair of calls toTcl_Preserve() andTcl_Release() should be wrapped around all uses of the interpreter; it is unsafe to reuse the interpreter onceTcl_Release() has been called. If an interpreter is stored inside a callback data structure, an appropriate deletion cleanup mechanism should be set up by the code that creates the data structure so that the interpreter is removed from the data structure (for example, by setting the field to NULL) when the interpreter is deleted. Otherwise, you may be using an interpreter that has been freed and whose memory may already have been reused.
All uses of interpreters in Tcl and Tk have already been protected. Extension writers should ensure that their code also properly protects any additional interpreters used, as described above.
PORTABILITY
Windows 10. Windows Server 2016. Windows Server 2019. Windows 11. Windows Server 2022. Windows Server 2025.
AVAILABILITY
PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition
SEE ALSO
- Functions:
Tcl_Preserve() ,Tcl_Release()
PTC MKS Toolkit 10.5 Documentation Build 40.