def deepsize(obj, max_depth=4):
 def _recurse(o, dct, depth):
  if ((max_depth >= 0) and (depth > max_depth)):
   return
  for ref in get_referents(o):
   idr = id(ref)
   if (not (idr in dct)):
    dct[idr] = (ref, getsizeof(ref, default=0))
    _recurse(ref, dct, (depth + 1))
 sizedict = {}
 _recurse(obj, sizedict, 0)
 size = (getsizeof(obj) + sum([p[1] for p in sizedict.values()]))
 return size

def deepsize ( obj , max_depth = 4 ) : def _recurse ( o , dct , depth ) : if ( ( max_depth >= 0 ) and ( depth > max_depth ) ) : return for ref in get_referents ( o ) : idr = id ( ref ) if ( not ( idr in dct ) ) : dct [ idr ] = ( ref , getsizeof ( ref , default = 0 ) ) _recurse ( ref , dct , ( depth + 1 ) ) sizedict = { } _recurse ( obj , sizedict , 0 ) size = ( getsizeof ( obj ) + sum ( [ p [ 1 ] for p in sizedict . values ( ) ] ) ) return size
get not only size of the given object .