mirror of
https://github.com/python/cpython.git
synced 2025-12-04 16:43:27 +00:00
Add text about circular references caused by storing frames in local
variables. This closes SF bug #543148.
This commit is contained in:
parent
95df3fd159
commit
99d17006c1
1 changed files with 16 additions and 0 deletions
|
|
@ -321,3 +321,19 @@ which occurs.}
|
||||||
Return a list of frame records for the stack below the current
|
Return a list of frame records for the stack below the current
|
||||||
exception.
|
exception.
|
||||||
\end{funcdesc}
|
\end{funcdesc}
|
||||||
|
|
||||||
|
Stackframes stored directly or indirectly in local variables can
|
||||||
|
easily cause reference cycles. Though the cycle detector will catch
|
||||||
|
these, destruction of the frames (and local variables) can be made
|
||||||
|
deterministic by removing the cycle in a \keyword{finally} clause.
|
||||||
|
This is also important if the cycle detector was disabled when Python
|
||||||
|
was compiled or using \function{gc.disable()}. For example:
|
||||||
|
|
||||||
|
\begin{verbatim}
|
||||||
|
def handle_stackframe_without_leak():
|
||||||
|
frame = inspect.currentframe()
|
||||||
|
try:
|
||||||
|
# do something with the frame
|
||||||
|
finally:
|
||||||
|
del frame
|
||||||
|
\end{verbatim}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue