Runtime Inspection Methods

frame.clear()

Clear references to locals of a completed frame to help break reference cycles. Executing frames and, in Python 3.13, suspended frames reject clearing. Not a general way to reset a running function.

Formal Syntax & Structure

python syntaxpython
frame.clear()

Return Value

None

Result of the inspection method.

Working Example

Example Snippetpython
import inspectdef f():    token = 'secret'    return inspect.currentframe()frame = f(); frame.clear()print('token' in frame.f_locals)
Python Reference