From f9b76033ba18ea26aeb6cde139bc192ad9cdbdba Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Tue, 23 Apr 2002 21:19:55 +0000 Subject: [PATCH] Add text about circular references caused by storing frames in local variables. This closes SF bug #543148. --- Doc/lib/libinspect.tex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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} -- 2.47.3