]> granicus.if.org Git - python/commitdiff
Add text about circular references caused by storing frames in local
authorFred Drake <fdrake@acm.org>
Tue, 23 Apr 2002 21:21:20 +0000 (21:21 +0000)
committerFred Drake <fdrake@acm.org>
Tue, 23 Apr 2002 21:21:20 +0000 (21:21 +0000)
variables.  This closes SF bug #543148.

Doc/lib/libinspect.tex

index 186fd586b35a3b0ea8544e869cbd9ff7c6ee5040..a1293f0e96a8a055a8c2663531b023d12874e6a2 100644 (file)
@@ -321,3 +321,19 @@ which occurs.}
   Return a list of frame records for the stack below the current
   exception.
 \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}