1. Python code gets converted into bytecode. Then bytecode is interpreted by the interpreter such as Cpython, jython etc.
  2. What is that entity that converts python code to bytecode?

Python Memory Management

Memory management differs in the implementation of python interpreter (CPython, Jython, etc).

This note includes memory management in CPython.

Everything in Python is an object which has pyobject as internal structure.

Python Application Memory

Python application gets memory from OS. It has following roughly structure.

  1. Non-object Memory for python internals objects.
  2. Object Memory for user objects.

Python Memory Structure

Memory structure

Memory allocated to Object memory is divided into:

  1. Arena
  2. Pools
  3. Blocks

Arena are big size memory allocated which has several pools storing same size blocks.

Arena, poll, block

Each pool maintain a double linked list to another pools.

Pool states

  1. usedpools
  2. fullpools
  3. freepools (empty)

usedpools contains references to pools which have some occupied blocks. fullpools has references to fully occupied pools. freepools have references to totally empty pools.

Pool block states

  1. free
  2. untouched
  3. allocated

References

  1. https://realpython.com/python-memory-management/#cpythons-memory-management