Object Size

Question

Function to determine the size of an object.

Solution

import cPickle
import sys

obj = range(10000)

def GetMemoryUsage(ob):
    s = cPickle.dumps(ob)
    memUsed = sys.getpymemalloced()
    ob2 = cPickle.loads(s)
    return sys.getpymemalloced() - memUsed

print GetMemoryUsage(obj)
Run this
Comments by Disqus