When the following functions return ``frame records,'' each record is a tuple of six items: the frame object, the filename, the line number of the current line, the function name, a list of lines of context from the source code, and the index of the current line within that list. The optional context argument specifies the number of lines of context to return, which are centered around the current line.
Stackframes stored directly or indirectly in local variables can easily cause reference cycles the garbage collector can't collect, leading to memory leaks. To avoid this, it's a good idea to explicitly remove the cycle in a finally clause. For example:
def handle_stackframe_without_leak(): frame = inspect.currentframe() try: # do something with the frame finally: del frame