Can you please explain Python dictionary memory usage?


The dictionary consists of a number of buckets. Each of these buckets contains

  • the hash code of the object currently stored (that is not predictable from the position of the bucket due to the collision resolution strategy used)
  • a pointer to the key object
  • a pointer to the value object

This sums up to at least 12 bytes on a 32bit machine and 24 bytes on a 64bit machine. The dictionary starts with 8 empty buckets. This is then resized by doubling the number of entries whenever its capacity is reached.

Updated on: 17-Jun-2020

568 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements