How can I check the memory usage of objects in iPython?
Unfortunately this is not possible, but there are a number of ways of approximating the answer:
for very simple objects (e.g. ints, strings, floats, doubles) which are represented more or less as simple C-language types you can simply calculate the number of bytes as with John Mulder's solution.
For more complex objects a good approximation is to serialize the object to a string using cPickle.dumps. The length of the string is a good approximation of the amount of memory required to store an object.
There is one big snag with solution 2, which is that objects usually contain references to other objects. For example a dict contains string-keys and other objects as values. Those other objects might be shared. Since pickle always tries to do a complete serialization of the object it will always over-estimate the amount of memory required to store an object.
If you are using a numpy array, then you can use the attribute ndarray.nbytes
to evaluate its size in memory:
from pylab import *
d = array([2,3,4,5])
d.nbytes
#Output: 32