Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 99d1700

Browse files
committed
Add text about circular references caused by storing frames in local
variables. This closes SF bug #543148.
1 parent 95df3fd commit 99d1700

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Doc/lib/libinspect.tex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,19 @@ \subsection{The interpreter stack
321321
Return a list of frame records for the stack below the current
322322
exception.
323323
\end{funcdesc}
324+
325+
Stackframes stored directly or indirectly in local variables can
326+
easily cause reference cycles. Though the cycle detector will catch
327+
these, destruction of the frames (and local variables) can be made
328+
deterministic by removing the cycle in a \keyword{finally} clause.
329+
This is also important if the cycle detector was disabled when Python
330+
was compiled or using \function{gc.disable()}. For example:
331+
332+
\begin{verbatim}
333+
def handle_stackframe_without_leak():
334+
frame = inspect.currentframe()
335+
try:
336+
# do something with the frame
337+
finally:
338+
del frame
339+
\end{verbatim}

0 commit comments

Comments
 (0)