I have a dict, its size is 198526.
sys.getsizeof(dic)) # 198526
class Actor(object):
def __init__(self):
pass
actor = Actor()
actor.__dict__.update(dic)
sys.getsizeof(actor.__dict__) #89850
Why actor.__dict__
< dict
?
I have a dict, its size is 198526.
sys.getsizeof(dic)) # 198526
class Actor(object):
def __init__(self):
pass
actor = Actor()
actor.__dict__.update(dic)
sys.getsizeof(actor.__dict__) #89850
Why actor.__dict__
< dict
?
Here's a possible explanation: Python dictionaries never shrink.
If that dictionary had more elements but then you removed some of them, the hash table won't be resized.
OTOH if you copy it or update another dictionary, then you might get a smaller (hash table) size.