Ipython and reference counting

It seems that ipython can save object references when I don't expect this.

Consider the following script ( grc.py ):

 import sys obj = [] print sys.getrefcount(obj) 

When I ran 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 happening? Where did the extra two links come from?

+4
source share
1 answer

Yes, IPython supports object references behind the scenes. Using% run, in particular, leaves links in machines that process modules.

We are working on this in a development version (which I hope will soon be 0.11) - see this issue for more information. Links will still be present, but there will be ways to get rid of them ( %reset to clear them all, or %xdel obj for one).

+3
source

All Articles