How To delete a tcl Interpreter?
c++, tcl
Solution
You must not use the C++ `delete` operator on a Tcl interpreter. Tcl's implementation is in C (for various reasons that don't matter to this question) so you must use C idioms when interacting with it. In particular, `Tcl_CreateInterp` is paired with `Tcl_DeleteInterp`; they're even documented on the same manual page. (Tcl doesn't guarantee to free the memory instantly when you delete the interpreter with that function, as it waits until there are no more uses of it on the stack, but if you're deleting it at a sane point then you'll be fine. Internally, `Tcl_DeleteInterp` eventually ends up calling `free()` on the interpreter structure, which is correct because the interpreter was allocated via `malloc()`.) If you want RAII-style memory management, you'll have to wrap it in a small class (a Boost `scoped_ptr` is almost perfect, except that you need a different destructor).
The other thing to watch out for from C++ is that Tcl interpreters are strictly thread bound; the Tcl library makes extensive use of thread-local data internally to reduce the number of global locks to a bare minimum (in particular, Tcl doesn't have any of the weird global lock problems of the C implementation of Python). An interpreter can only ever be accessed or deleted from the same thread that created it.
Problem
I am having an application in c++ and I am using tcl interpreter for this.I have created a tcl interpreter for my application using ``` Tcl_Interp *_tclInterp = Tcl_CreateInterp(); ``` And I have intialized this interpreter in a function. I want to delete/unset the interpreter at last inside the same function in which I have intialized it. So that when I do a ``` Get("tcl"); ``` call I donot get the same interpreter. So my question is how to delete/unset the tcl interpreter.