Skip to content
Tcl Source Code Artifact [732cb100b7]
Login

Artifact [732cb100b7]

Artifact 732cb100b7b92a676b0d57d936e908b688eaa80ed745607f1e0355b385834799:


---
CommandName: Tcl_CallWhenDeleted
ManualSection: 3
Version: 7.0
TclPart: Tcl
TclDescription: Tcl Library Procedures
Links:
 - Tcl_CreateExitHandler(3)
 - Tcl_CreateThreadExitHandler(3)
Keywords:
 - callback
 - cleanup
 - delete
 - interpreter
Copyright:
 - Copyright (c) 1993 The Regents of the University of California.
 - Copyright (c) 1994-1996 Sun Microsystems, Inc.
---

# Name

Tcl\_CallWhenDeleted, Tcl\_DontCallWhenDeleted - Arrange for callback when interpreter is deleted

# Synopsis

::: {.synopsis} :::
**#include <tcl.h>**
[Tcl\_CallWhenDeleted]{.ccmd}[interp, proc, clientData]{.cargs}
[Tcl\_DontCallWhenDeleted]{.ccmd}[interp, proc, clientData]{.cargs}
:::

# Arguments

::: {.arguments} :::

[\*interp]{.carg .in type="Tcl_Interp"}
: Interpreter with which to associated callback.

[\*proc]{.carg .in type="Tcl_InterpDeleteProc"}
: Procedure to call when *interp* is deleted.

[\*clientData]{.carg .in type="void"}
: Arbitrary one-word value to pass to *proc*.


:::

# Description

**Tcl\_CallWhenDeleted** arranges for *proc* to be called by [Tcl\_DeleteInterp][CrtInterp] if/when *interp* is deleted at some future time.  *Proc* will be invoked just before the interpreter is deleted, but the interpreter will still be valid at the time of the call. *Proc* should have arguments and result that match the type **Tcl\_InterpDeleteProc**:

```
typedef void Tcl_InterpDeleteProc(
        void *clientData,
        Tcl_Interp *interp);
```

The *clientData* and *interp* parameters are copies of the *clientData* and *interp* arguments given to **Tcl\_CallWhenDeleted**. Typically, *clientData* points to an application-specific data structure that *proc* uses to perform cleanup when an interpreter is about to go away. *Proc* does not return a value.

**Tcl\_DontCallWhenDeleted** cancels a previous call to **Tcl\_CallWhenDeleted** with the same arguments, so that *proc* will not be called after all when *interp* is deleted. If there is no deletion callback that matches *interp*, *proc*, and *clientData* then the call to **Tcl\_DontCallWhenDeleted** has no effect.

Note that if the callback is being used to delete a resource that *must* be released on exit, [Tcl\_CreateExitHandler][Exit3] should be used to ensure that a callback is received even if the application terminates without deleting the interpreter.


[CrtInterp]: CrtInterp.md
[Exit3]: Exit3.md