Memory Management in Python: 3 Popular Interview Questions

Dive into the internal mechanisms

Yang Zhou
TechToFreedom

--

Memory Management in Python: 3 Popular Interview Questions
Image by Gerd Altmann from Pixabay

The memory management is one of the most popular interview topics for Python developers. Because questions about it can test a programmer’s understanding of some internal mechanisms of Python.

Some common questions are:

  • How to get the memory address of a Python object (or vice versa)?
  • How does Python collect garbage (useless objects)?
  • How does Python optimise memory usages (interning mechanism)?

If you cannot answer the above questions clearly yet, no worries at all.

Because this article will explain them from elementary to profound. After reading, acing your tech interviews will be just a piece of cake. 🍰

Friendly Remind: This article is based on the commonly used implementation of Python — CPython. Other Python implementations (PyPy, Jython, and so on) may have different results.

How To Get the Memory Address of a Python Object (or Vice Versa)?

This is the simplest question. In CPython, we can use the built-in id() function to get the memory address of an object:

>>> punk=2077
>>> id(punk)…

--

--