ipython and reference counts

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?

Answers


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 (%reset to clear them all, or %xdel obj for a single one).


Need Your Help

RaphaelJS / CSS - Animating text/numbers

javascript css animation svg raphael

So, I am just diving into simple web animations for a game, and I am looking for advice. Eventually, I'll get a good grip on beziers and arcs and learn how to animate along a path to get some nice ...

Getting string value from SQL function inside a CLR

c# .net sql-server tsql sqlclr

Attempted (non-working) solution included below.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.