It would appear that ipython may be retaining references to objects when I’m not expecting it to.
Consider the following script (grc.py):
import sys
obj = []
print sys.getrefcount(obj)
When I run it in ipython:
Python 2.7.1 |EPD 7.0-2 (64-bit)| (r271:86832, Nov 29 2010, 13:51:37)
In [1]: %run grc.py
2
In [2]: print sys.getrefcount(obj)
4
What’s going on? Where did the extra two references come from?
Yes, IPython does maintain references to objects behind the scenes. Using %run in particular leaves references in the machinery that handles modules.
We’re working on it in the development version (which will hopefully become 0.11 soon) – see this issue for more information. The references will still be there, but there’ll be ways to get rid of them (
%resetto clear them all, or%xdel objfor a single one).