From: Fred Drake Date: Tue, 23 Apr 2002 21:19:55 +0000 (+0000) Subject: Add text about circular references caused by storing frames in local X-Git-Tag: 2.1~54 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9b76033ba18ea26aeb6cde139bc192ad9cdbdba;p=thirdparty%2FPython%2Fcpython.git Add text about circular references caused by storing frames in local variables. This closes SF bug #543148. --- diff --git a/Doc/lib/libinspect.tex b/Doc/lib/libinspect.tex index 6101ad87e0c2..5b57ba9935e6 100644 --- a/Doc/lib/libinspect.tex +++ b/Doc/lib/libinspect.tex @@ -287,3 +287,18 @@ context to return, which are centered around the current line. 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 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 \keyword{finally} clause. For +example: + +\begin{verbatim} +def handle_stackframe_without_leak(): + frame = inspect.currentframe() + try: + # do something with the frame + finally: + del frame +\end{verbatim}