Skip to content

size

getsize Link

getsize(obj)

sum size of object & members.

Source code in spectral_clustering/utils/size.py
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
def getsize(obj):
    """sum size of object & members."""
    if isinstance(obj, (type, ModuleType, FunctionType)):
        raise TypeError('getsize() does not take argument of type: '+ str(type(obj)))
    seen_ids = set()
    size = 0
    objects = [obj]
    while objects:
        need_referents = []
        for obj in objects:
            if not isinstance(obj, (type, ModuleType, FunctionType)) and id(obj) not in seen_ids:
                seen_ids.add(id(obj))
                size += sys.getsizeof(obj)
                need_referents.append(obj)
        objects = get_referents(*need_referents)
    return size